[System] You are a helpful assistant.

[User] git - the stupid content tracker  git-credential-store

[Assistant] Helper to store credentials on disk


[System] You are a helpful assistant.

[User]
My new Github page isn't showing up

So I'm following this guide here to create a Github page
I created a repository, cloned it to my project directory and pushed, finally got to this last step:
Fire up a browser and go to http://username.github.io. Give it a couple of minutes for your page to show up—there will be a delay this very first time. In the future, changes will show up pretty much instantly.

My Github repo link is this:
https://github.com/leongaban/gabanco
So I assumed my Github page link would be either:
http://leongaban.gabanco.github.io/
or
http://leongaban.github.io/
However neither link is working at the moment :(
Anyone create a Github page before? Eventually I want to try out Jekyll on it.

[Assistant]
Try to push an empty commit and refresh the page. It should work.
git commit --allow-empty -m "Trigger rebuild"
git push


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  diff.submodule

[Assistant]
Specify the format in which differences in submodules are
shown.  The "short" format just shows the names of the commits
at the beginning and end of the range. The "log" format lists
the commits in the range like git-submodule summary does. The "diff" format shows an inline diff of the changed
contents of the submodule. Defaults to "short".


[System] You are a helpful assistant.

[User]
How to use Dockerfile in Gitlab CI

Using gitlab-ci for my node/react app, I'm trying to use phusion/passenger-nodejs as the base docker image
I can specify this easily in .gitlab-ci.yml:
image: phusion/passenger-nodejs:latest

variables:
  HOME: /root

cache:
  paths:
  - node_modules/

stages:
  - build
  - test
  - deploy

set_environment:
  stage: build
  script:
    - npm install
  tags:
  - docker

test_node:
  stage: test
  script:
    - npm install
    - npm test
  tags:
    - docker

However, Phusion Passenger expects you to make configuration changes, e.g. python support, using their special init process, etc. in the Dockerfile.
#FROM phusion/passenger-ruby24:<VERSION>
#FROM phusion/passenger-jruby91:<VERSION>
FROM phusion/passenger-nodejs:<VERSION>
#FROM phusion/passenger-customizable:<VERSION>

# Set correct environment variables.
ENV HOME /root

# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]

# If you're using the 'customizable' variant, you need to explicitly opt-in
# for features.
#
# N.B. these images are based on https://github.com/phusion/baseimage-docker,
# so anything it provides is also automatically on board in the images below
# (e.g. older versions of Ruby, Node, Python).
#
# Uncomment the features you want:
#
#   Ruby support
#RUN /pd_build/ruby-2.0.*.sh
#RUN /pd_build/ruby-2.1.*.sh
#RUN /pd_build/ruby-2.2.*.sh
#RUN /pd_build/ruby-2.3.*.sh
#RUN /pd_build/ruby-2.4.*.sh
#RUN /pd_build/jruby-9.1.*.sh
#   Python support.
RUN /pd_build/python.sh
#   Node.js and Meteor standalone support.
#   (not needed if you already have the above Ruby support)
RUN /pd_build/nodejs.sh

# ...put your own build instructions here...

# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Is there a way to use a Dockerfile with gitlab-ci? Is there a good work around other than apt-get install and adding shell scripts?

[Assistant]
Yes, create a second Gitlab repository where you place your Dockerfile in. There you add a gitlab-ci.yml file with a script command that builds you modified image and push it to your private registry or the Gitlab embedded Docker registry, eg:
script:
  docker build . -t http://myregistry:5000/mymodified image
  docker push http://myregistry:5000/mymodified
Inside your other Gitlab repository, change the image: line accordingly:
image: http://myregistry:5000/mymodified
Information on the Gitlab embedded Docker registry can be found here -> here


[System] You are a helpful assistant.

[User]
Git command to show which specific files are ignored by .gitignore
I am getting my feet wet with Git and have the following issue:
My project source tree:
/
|
+--src/
+----refs/
+----...
|
+--vendor/
+----...

I have code (currently MEF) in my vendor branch that I will compile there and then move the references into /src/refs which is where the project picks them up from.
My issue is that I have my .gitignore set to ignore *.dll and *.pdb.  I can do a git add -f bar.dll to force the addition of the ignored file which is ok, the problem is I can not figure out to list what files exist that are ignored.
I want to list the ignored files to make sure that I don't forget to add them.
I have read the man page on git ls-files and can not make it work. It seems to me that git ls-files --exclude-standard -i should do what I want.  What am I missing?

[Assistant]
Notes:

xiaobai's answer is simpler (git1.7.6+): git status --ignored
(as detailed in "Is there a way to tell git-status to ignore the effects of .gitignore files?")

Also interesting (mentioned in qwertymk's answer), you can also use the git check-ignore -v command, at least on Unix (doesn't work in a CMD Windows session, but works in a Windows CMD git bash session)
git check-ignore -- *
git check-ignore -v -- *

The second one displays the actual rule of the .gitignore which makes a file to be ignored in your git repo.
On Unix, using "What expands to all files in current directory recursively?" and a bash4+:
git check-ignore **/*

(or a find -exec command)
Note: https://stackoverflow.com/users/351947/Rafi B. suggests in the comments to avoid the (risky) globstar:
git check-ignore -v $(find . -type f -print)

Make sure to exclude the files from the .git/ subfolder though.
CervEd suggests in the comments, to avoid .git/:
find . -not -path './.git/*' | git check-ignore --stdin

Original answer (2009)
git ls-files -i

should work, except its source code indicates:
if (show_ignored && !exc_given) {
                fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
                        argv[0]);

exc_given?
It turns out it needs one more parameter after the -i to actually list anything.
Try:
git ls-files -i --exclude-from=[Path_To_Your_Global].gitignore

(but that would only list your cached (non-ignored) object, with a filter, so that is not quite what you want)

Example:
$ cat .git/ignore
# ignore objects and archives, anywhere in the tree.
*.[oa]
$ cat Documentation/.gitignore
# ignore generated HTML files,
*.html
# except foo.html which is maintained by hand
!foo.html
$ git ls-files --ignored \
    --exclude='Documentation/*.[0-9]' \
    --exclude-from=.git/ignore \
    --exclude-per-directory=.gitignore

Actually, in my 'gitignore' file (called 'exclude'), I find a command line that could help you:
F:\prog\git\test\.git\info>type exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~

So....
git ls-files --ignored --exclude-from=.git/info/exclude
git ls-files -i --exclude-from=.git/info/exclude

git ls-files --others --ignored --exclude-standard
git ls-files -o -i --exclude-standard

Should do the trick.
(Thanks to honzajde pointing out in the comments that git ls-files -o -i --exclude-from... does not include cached files: only git ls-files -i --exclude-from... (without -o) does.)
As mentioned in the ls-files man page, --others is the important part, to show you non-cached, non-committed, normally ignored files.
--exclude_standard is not just a shortcut, but a way to include all standard "ignored patterns" settings.

exclude-standard
Add the standard git exclusions: .git/info/exclude, .gitignore in each directory, and the user's global exclusion file.

Git 2.44 (Q1 2024), batch 13, clarifies the documentation where the --exclude-per-directory option was marked as deprecated, which confused readers into thinking there may be a plan to remove it in the future, which was not our intention.
See commit 0009542 (24 Jan 2024) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit bbc8c05, 02 Feb 2024)

ls-files: avoid the verb "deprecate" for individual options

When e750951 ("ls-files: guide folks to --exclude-standard over other --exclude* options", 2023-01-13, Git v2.40.0-rc0 -- merge listed in batch #13) updated the documentation to give greater visibility to the --exclude-standard option, it marked the --exclude-per-directory option as "deprecated".
While it is technically correct that being deprecated does not necessarily mean it is planned to be removed later, it seems to cause confusion to readers, especially when we merely mean
The option Y can be used to achieve the same thing as the option
X much simpler. To those of you who aren't familiar with either
X or Y, we would recommend to use Y when appropriate.

This is especially true for --exclude-standard vs the combination of more granular --exclude-from and --exclude-per-directory options.
It is true that one common combination of the granular options can be obtained by just giving the former, but that does not necessarily mean a more granular control is not necessary.
State the reason why we recommend readers --exclude-standard in the description of --exclude-per-directory, instead of saying that the option is deprecated.
Also, spell out the recipe to emulate what --exclude-standard does, so that the users can give it minute tweaks (like "do the same as Git Porcelain, except I do not want to read the global exclusion file from core.excludes").

git ls-files now includes in its man page:

directory and its subdirectories in .  If you are
trying to emulate the way Porcelain commands work, using
the --exclude-standard option instead is easier and more
thorough.

git ls-files now includes in its man page:

Generally, you should be able to use --exclude-standard when you
want the exclude rules applied the same way as what Porcelain
commands do.  To emulate what --exclude-standard specifies, you
can give --exclude-per-directory=.gitignore, and then specify:

The file specified by the core.excludesfile configuration
variable, if exists, or the $XDG_CONFIG_HOME/git/ignore file.

The $GIT_DIR/info/exclude file.

via the --exclude-from= option.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --merge

[Assistant]
Show commits touching conflicted paths in the range HEAD...<other> ,
where <other> is the first existing pseudoref in MERGE_HEAD , CHERRY_PICK_HEAD , REVERT_HEAD or REBASE_HEAD . Only works
when the index has unmerged entries. This option can be used to show
relevant commits when resolving conflicts from a 3-way merge.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  branch.autoSetupRebase

[Assistant]
When a new branch is created with git branch , git switch or git checkout that tracks another branch, this variable tells Git to set
up pull to rebase instead of merge (see "branch.<name>.rebase").
When never , rebase is never automatically set to true.
When local , rebase is set to true for tracked branches of
other local branches.
When remote , rebase is set to true for tracked branches of
remote-tracking branches.
When always , rebase will be set to true for all tracking
branches.
See "branch.autoSetupMerge" for details on how to set up a
branch to track another branch.
This option defaults to never.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  <tag>

[Assistant] a valid tag name (i.e. a refs/tags/<tag> reference).


[System] You are a helpful assistant.

[User] git-show - Show various types of objects  %S

[Assistant]
ref name given on the command line by which the commit was reached
(like git log --source ), only works with git log


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --simplify-merges

[Assistant]
First, build a history graph in the same way that --full-history with parent rewriting does (see above). Then simplify each commit C to its replacement C' in the final
history according to the following rules: Set C' to C . Replace each parent P of C' with its simplification P' .  In
the process, drop parents that are ancestors of other parents or that are
root commits TREESAME to an empty tree, and remove duplicates, but take care
to never drop all parents that we are TREESAME to. If after this parent rewriting, C' is a root or merge commit (has
zero or >1 parents), a boundary commit, or !TREESAME, it remains.
Otherwise, it is replaced with its only parent. The effect of this is best shown by way of comparing to --full-history with parent rewriting.  The example turns into: .-A---M---N---O
	 /     /       /
	I     B       D
	 \   /       /
	  `---------' Note the major differences in N , P , and Q over --full-history : N 's parent list had I removed, because it is an ancestor of the
other parent M .  Still, N remained because it is !TREESAME. P 's parent list similarly had I removed. P was then
removed completely, because it had one parent and is TREESAME. Q 's parent list had Y simplified to X . X was then removed, because it
was a TREESAME root. Q was then removed completely, because it had one
parent and is TREESAME.


[System] You are a helpful assistant.

[User]
Unicode / emojis in Github markdown

I just made a failed attempt to put unicode in Github markdown (in a README.md file) in my project.
I tried this:
(U+262E)

but it was not interpreted as unicode. Is there a way to put unicode characters in Github markdown?

[Assistant]
I believe the correct answer is to use unicode characters of the following (decimal) form
►
˿
ॠ

the above become:
►
˿
ॠ
Try it for yourself on Github and see. You have to paste the raw character strings, not the unicode symbol itself. It's not about what shows up in your editor, it's what actually displays on github.com.


[System] You are a helpful assistant.

[User]
How can I change the remote/target repository URL on Windows? [duplicate]
This question already has answers here:

How do I change the URI (URL) for a remote Git repository?

                                (34 answers)

Closed 10 years ago.

I created a local GIT repository on Windows. Let's call it AAA. I staged, committed, and pushed the contents to GitHub. [email protected]:username/AAA.git
I realized I made a mistake with the name.
On GitHub, I renamed it to [email protected]:username/BBB.git
Now, on my Windows machine, I need to change [email protected]:username/AAA.git to [email protected]:username/BBB.git because the settings are still trying to "push" to [email protected]:username/AAA.git but I need to push to [email protected]:username/BBB.git now.
How could I do that?

[Assistant] git remote set-url origin <URL>


[System] You are a helpful assistant.

[User]
Gitlab-runner local build - login from non TTY device

I'm trying to build my project locally using gitlab-runner on Linux.
docker-build:
  stage: build
  image: docker:latest
  script:
    - docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY # user "gitlab-ci-token" is automatically created by GitLab
    - docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME" target/
    - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME"

Unfortunately my attempts end with error about "docker login" not being able to perform interactive login from non-TTY device.
$ gitlab-ci-multi-runner exec docker --docker-privileged docker-build
Running with gitlab-ci-multi-runner 1.11.1 (a67a225)
  on  ()
Using Docker executor with image docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Waiting for services to be up and running...
Pulling docker image docker:latest ...
Running on runner--project-1-concurrent-0 via vanqyard...
Cloning repository...
Cloning into '/builds/project-1'...
done.
Checking out 70187b2d as docker-basic-conf...
Skipping Git submodules setup
Checking cache for docker-build/docker-basic-conf...
Successfully extracted cache
$ docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
Error: Cannot perform an interactive login from a non TTY device
ERROR: Job failed: exit code 1
FATAL: exit code 1

My question is has anybody stumbled upon this issue and how to succesfunlly perform build?

[Assistant]
Probably not linked to the problem here, but some people might encounter the exact same message when trying a docker login from a Linux like terminal on Windows such as Git bash or Docker quickstart terminal or even Cygwin.
The trick here is to use winpty docker login


[System] You are a helpful assistant.

[User]
How can I remove all files in my git repo and update/push from my local git repo?
Is it possible to remove all files in a repository and update it with only the files I have in my local machine? The reason is that, there are certain files that is not necessary in my github and so I want to remove those files. Instead of removing the files one by one, I wanted to see if its possible to just remove all files in my git repo and update/push with only the files in my local machine. Hope its clear. Thanks.

[Assistant]
You could do it like this:
cd /tmp
git clone /your/local/rep  # make a temp copy
cd rep
git rm -r *                # delete everything
cp -r /your/local/rep/* .  # get only the files you want
git add *                  # add them again
git status                 # everything but those copied will be removed
git commit -a -m 'deleting stuff'
cd /your/local/rep
git pull /tmp/rep          # now everything else has been removed

There's probably a oneliner for that…


[System] You are a helpful assistant.

[User]
Git: See my last commit
I just want to see the files that were committed in the last commit exactly as I saw the list when I did git commit. Unfortunately searching for
git "last commit" log

in Google gets me nowhere. And
git diff HEAD^..HEAD

is not what I need, of course, since it spews the guts of the change too.

[Assistant]
As determined via comments, it appears that the OP is looking for
$ git log --name-status HEAD^..HEAD

This is also very close to the output you'd get from svn status or svn log -v, which many people coming from subversion to git are familiar with.
--name-status is the key here; as noted by other folks in this question, you can use git log -1, git show, and git diff to get the same sort of output. Personally, I tend to use git show <rev> when looking at individual revisions.


[System] You are a helpful assistant.

[User]
git clone and checkout in a single command
The following is the command I use to checkout a specific commit.
git clone git://repo.git/repo123
git checkout <commitID>

I want to do the above in one step - using a git clone command only.
The reason why I want to do this is, repo123 is very huge. So checking out the commit I want will save me a lot of time.
I am aware of --depth option. But in this case, it is of no use. Can anyone tell me how to do it?

[Assistant]
git clone u://r/l --branch x

still clones everything but sets the local HEAD to that branch so it's the one checked out.
Source:

--branch <name>
-b <name>
  Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to <name> branch instead. In a non-bare repository, this is the branch that will be checked out. --branch can also take tags and detaches the HEAD at that commit in the resulting repository.


[System] You are a helpful assistant.

[User]
why is Issues tab not present in my repo's github page?

I want to create issues in a github repo to correct technical debt in the repo. I am not able to see the issues tab. For other repos the issues tab present below the pull request tab. How can I enable the issues tab for my repo?

[Assistant] You have to enable the Issues first. You can do that by clicking to Settings and enable the Issues section. Then you can use it.


[System] You are a helpful assistant.

[User] git-blame - Show what revision and author last modified each line of a file  -c

[Assistant] Use the same output mode as git-annotate (Default: off).


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  gpg.minTrustLevel

[Assistant]
Specifies a minimum trust level for signature verification.  If
this option is unset, then signature verification for merge
operations requires a key with at least marginal trust.  Other
operations that perform signature verification require a key
with at least undefined trust.  Setting this option overrides
the required trust-level for all operations.  Supported values,
in increasing order of significance: undefined never marginal fully ultimate


[System] You are a helpful assistant.

[User] git-update-index - Register file contents in the working tree to the index  --verbose

[Assistant] Report what is being added and removed from the index.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  --no-type

[Assistant]
Un-sets the previously set type specifier (if one was previously set). This
option requests that git config not canonicalize the retrieved variable. --no-type has no effect without --type=<type> or --<type> .


[System] You are a helpful assistant.

[User] git-fsck - Verifies the connectivity and validity of the objects in the database

[Assistant] NAME git-fsck - Verifies the connectivity and validity of the objects in the database


[System] You are a helpful assistant.

[User] git-fast-import - Backend for fast Git data importers  cat-blob

[Assistant] Causes fast-import to print a blob in cat-file --batch format to the file descriptor set with --cat-blob-fd or stdout if unspecified.


[System] You are a helpful assistant.

[User]
Switching branch on Xcode 9
I am having trouble finding the menu item to switch branch using Xcode 9. The working copies menu seems to have disappeared. Any ideas?
Xcode 9

Xcode 8

[Assistant]
Press ⌘2 to open the new Source Control Navigator.
Right-click on the master icon.

To switch to a different branch

Right-click on a non-current branch
Choose Checkout...
Press ↩ or click on the Checkout button.


[System] You are a helpful assistant.

[User] git-grep - Print lines matching a pattern  --exclude-standard

[Assistant]
Do not pay attention to ignored files specified via the .gitignore mechanism.  Only useful when searching files in the current directory
with --no-index .


[System] You are a helpful assistant.

[User]
What is the difference between git pull and git fetch + git rebase?
Another question says that git pull is like a git fetch + git merge.
But what is the difference between git pull and git fetch + git rebase?

[Assistant]
It should be pretty obvious from your question that you're actually just asking about the difference between git merge and git rebase.
So let's suppose you're in the common case - you've done some work on your master branch, and you pull from origin's, which also has done some work. After the fetch, things look like this:
- o - o - o - H - A - B - C (master)
               \
                P - Q - R (origin/master)

If you merge at this point (the default behavior of git pull), assuming there aren't any conflicts, you end up with this:
- o - o - o - H - A - B - C - X (master)
               \             /
                P - Q - R --- (origin/master)

If on the other hand you did the appropriate rebase, you'd end up with this:
- o - o - o - H - P - Q - R - A' - B' - C' (master)
                          |
                          (origin/master)

The content of your work tree should end up the same in both cases; you've just created a different history leading up to it. The rebase rewrites your history, making it look as if you had committed on top of origin's new master branch (R), instead of where you originally committed (H). You should never use the rebase approach if someone else has already pulled from your master branch.
Finally, note that you can actually set up git pull for a given branch to use rebase instead of merge by setting the config parameter branch.<name>.rebase to true. You can also do this for a single pull using git pull --rebase.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  first-parent, 1

[Assistant]
Show full diff with respect to first parent. This is the same
format as --patch produces for non-merge commits.


[System] You are a helpful assistant.

[User]
Duplicating git client hooks on the server side

I've defined a post-commit hook in .git/hooks that I want to also execute on the server side (Gitlab.com in my case).
Background: I'm using gitinfo2 along with a post-commit hook in a LaTeX project to quote info about the latest git tag within the pdf. This works well on my computer, but fails when I push the repo to Gitlab.
It doesn't cause an error, but gives the following warning, which basically means that the git hook never executed.
Package gitinfo2 Warning: I can't find the file '.git/gitHeadInfo.gin'.
(gitinfo2)                All git metadata has been set to '(None)'.

From what I've read online so far, client side git hooks don't execute on the server - but why not? In a situation like this, I would want the hook to execute on both the client and the server.
So, basically, I want the sequence of events to be like this:

I make a commit of the .tex file.
I push the commit to Gitlab.
Once it's at Gitlab, the git hook is executed leading to a file called gitHeadInfo.gin being created in the .git folder.
The latex document is built using Gitlab CI, with the gitinfo package helping to pull the git version info from gitHeadInfo.gin.
The pdf is deployed to Gitlab Pages.

I've got everything working except step 3. So, my current workaround is to build the pdf on my computer as well and commit it rather than relying on Gitlab CI.
Contents of the git hook:
#!/bin/sh
# Copyright 2015 Brent Longborough
# Part of gitinfo2 package Version 2
# Release 2.0.7 2015-11-22
# Please read gitinfo2.pdf for licencing and other details
# -----------------------------------------------------
# Post-{commit,checkout,merge} hook for the gitinfo2 package
#
# Get the first tag found in the history from the current HEAD
FIRSTTAG=$(git describe --tags --always --dirty='-*' 2>/dev/null)
# Get the first tag in history that looks like a Release
RELTAG=$(git describe --tags --long --always --dirty='-*' --match '[0-9]*.*' 2>/dev/null)
# Hoover up the metadata
git --no-pager log -1 --date=short --decorate=short \
    --pretty=format:"\usepackage[%
        shash={%h},
        lhash={%H},
        authname={%an},
        authemail={%ae},
        authsdate={%ad},
        authidate={%ai},
        authudate={%at},
        commname={%cn},
        commemail={%ce},
        commsdate={%cd},
        commidate={%ci},
        commudate={%ct},
        refnames={%d},
        firsttagdescribe={$FIRSTTAG},
        reltag={$RELTAG}
    ]{gitexinfo}" HEAD > .git/gitHeadInfo.gin

[Assistant]
client side git hooks don't execute on the server - but why not?

Generally, you are pushing to a bare repo (a repo without working tree, where you cannot do any commit directly)
So server-side commits are more about enforcing policies than creating new commits.
If you really needed new content to be created on the server side (especially one you have no direct control, like GitLab.com), you would need:

either to activate some kind of server-side hook, which is for now only available at GitHub, with GitHub actions.
or setup a listener to a GitLab webhook: that webhook would call (on each push events) your listener which could in turn get the latest history, do any modification you need, create new commit and push back.


[System] You are a helpful assistant.

[User] git-blame - Show what revision and author last modified each line of a file  -b

[Assistant]
Show blank SHA-1 for boundary commits.  This can also
be controlled via the blame.blankBoundary config option.


[System] You are a helpful assistant.

[User]
Why doesn't git pull bring back directories that I've deleted?
I've just started learning how to use git today, progressing well.
As an experiment, I used push to upload two directories (containing two files each) and two files in the root directory. This worked fine.
I then deleted one of the two directories that I have locally (but not on git). When I use git status it seems to be aware of this:

deleted: test/Testfile.as
deleted: test/Testile2.as

But when I use git pull to get my files back, they don't seem to return to my local folder. I've also tried git fetch.
The only way I seem to be able to get everything back is git clone, but that doesn't seem logical as I need to delete my master directory locally and then clone it back again (or  alternatively specify a new location for the cloned files).
What is the appropriate way to retrieve files and folders from github that have been deleted locally?

[Assistant]
git pull just merges the fetched commits in your working directory and will not restore your deleted directory ( but might warn you about conflicts.)
If you have deleted the folders in your working directory, you have to do:
git checkout -- test

to get it back.
Or you can do git reset --hard to completely bring your working directory to HEAD state.


[System] You are a helpful assistant.

[User] git-read-tree - Reads tree information into the index  --reset

[Assistant]
Same as -m, except that unmerged entries are discarded instead
of failing.  When used with -u , updates leading to loss of
working tree changes or untracked files or directories will not
abort the operation.


[System] You are a helpful assistant.

[User]
.gitignore for Visual Studio Projects and Solutions
Which files should I include in .gitignore when using Git in conjunction with Visual Studio Solutions (.sln) and Projects?

[Assistant]
See the official GitHub's "Collection of useful .gitignore templates".
The .gitignore for Visual Studio can be found here:
https://github.com/github/gitignore/blob/main/VisualStudio.gitignore


[System] You are a helpful assistant.

[User]
How to list organization's private repositories via GitHub API?

I'm trying to get a list of an organization's all repositories, including private ones. (Or to be more specific, all of the private repositories a certain user has access to.)
Reqesting info for the organization (https://api.github.com/orgs/acme?access_token=[...]) shows that there indeed are plenty of private repositories:
...
"public_repos": 5,
"total_private_repos": 68,
"owned_private_repos": 68,
...

(The access token I'm using had been previously generated using the API for username/passwd.)
But whatever I try to list the repos...
https://api.github.com/orgs/acme/repos?access_token=[...]

...GitHub API just returns the 5 public repositories. (Documentation says type=all is default. Also tried adding the parameter type=private; no difference.)
Any idea what I'm doing wrong?
The user to whom the access token was generated in fact has Push & Pull access to just some  of the organization's private repositories, but none of those appear in the list I get (just the 5 public repositories).

[Assistant] Everything you are doing is OK. However, when creating OAuth tokens for authentication, be sure that you are defining the right scopes. Each scope defines a specific set of permitted actions (information you can read/write), so you should check that you are creating the token with the repo scope.


[System] You are a helpful assistant.

[User]
Combine the first two commits of a Git repository?
Suppose you have a history containing the three commits A, B and C:
A-B-C

I would like to combine the two commits A and B to one commit AB:
AB-C

I tried
git rebase -i A

which opens up my editor with the following contents:
pick e97a17b B
pick asd314f C

I change this to
squash e97a17b B
pick asd314f C

Then Git 1.6.0.4 says:
Cannot 'squash' without a previous commit

Is there a way or is this just impossible?

[Assistant]
Use git rebase -i --root
as of Git version 1.7.12.
In the interactive rebase file, change the second line of commit B to squash and leave the other lines at pick:
pick f4202da A
squash bea708e B
pick a8c6abc C

This will combine the two commits A and B to one commit AB.
Found in this answer.


[System] You are a helpful assistant.

[User]
Git rebase interactive the last n commits
I have made a bunch of unpushed commits in my feature branch and now want to reorder and partly squash belonging commits visually. I reckon the solution somehow lies in the Git interactive, but how to invoke it?
$ git rebase --interactive --onto <the-ID-of-the-first-commit-to-rewrite>

just pops up the VI with a
noop

content followed by commented information. After exiting, my head is reset to the specified commit.
How to correctly trigger the interactive rebase for modifying the commits since a certain commit?

[Assistant]
you should use
git rebase --interactive <sha1>

where <sha1> should not be the sha of the first commit you want to rewrite, but the sha of the commit just before.
if your history looks like this:
pick 43576ef last commit
...
pick 5116d42 first commit to rewrite
pick cb85072 last good commit

There are two different ways to indicate the commit on which to rebase:
git rebase -i cb85072
git rebase -i 5116d42^

where

^ means the commit just before.
-i is just short for --interactive


[System] You are a helpful assistant.

[User]
How to relaunch GitHub check without pushing new commits?

I'm currently using GitHub with a basic Jenkins integration (with the GitHub plugin): each time I push something, my Jenkins tests are triggered and the status is reported to GitHub.
For some dirty reasons (and I know the root cause is here), my tests could randomly fail and then report a failed status to GitHub (which blocked the possibility to merge the PR: and that's the expected behavior).
Do you know if it's possible to relaunch the tests without pushing a new commit? Because I know if I relaunch the tests, they will pass.

[Assistant]
Update: you can also push an empty commit to your branch to re-trigger status checks: git commit -m "retrigger checks" --allow-empty and then git push <branchname>
Update: You can create an alias in the gitconfig file to make it simpler:
retriggerchecks = "!f() { git commit -m\"Retriggering checks\" --allow-empty && git push ;}; f"

rtc = "!f() { git retriggerchecks ;}; f"

One longname alias and a short one.
You can also do this by closing and then re-opening the Pull Request. This will cause all status checks to run again on the same commit.


[System] You are a helpful assistant.

[User] git-show - Show various types of objects  %gn

[Assistant] reflog identity name


[System] You are a helpful assistant.

[User] git - the stupid content tracker  gittutorial-2

[Assistant] A tutorial introduction to Git: part two


[System] You are a helpful assistant.

[User]
Displaying latex equation in gitlab wiki using the markdown editor

I am interested in building a wiki for my scientific computing code on gitlab which needs me to write equations and render them in the wiki in gitlab.
How to do this.
I tried to paste the mathjax rendering script but it doesn't work.
Can KaTeX be used anyhow ?
$$
  \partial_t \int_{\Omega} \mathbf{q} d \Omega =
  \int_{\partial \Omega} \mathbf{f} (
  \mathbf{q}) \cdot \mathbf{n}d \partial
  \Omega - \int_{\Omega} hg \nabla z_b
$$

[Assistant]
GitLab supports KaTex from GitLab CE 8.15 using code backticks.
Documentation is here and the
Relevant discussion are on merge request 8003.
Here is the current way to use equations in GitLab


[System] You are a helpful assistant.

[User] git - the stupid content tracker  git-blame

[Assistant] Show what revision and author last modified each line of a file


[System] You are a helpful assistant.

[User]
Remove and ignore all files that have an extension from a git repository
I'm working on a django project with a few other developers and we have recently realized that all the .pwc files in our app cause the commits and repository to be cluttered.
Is there any way I can remove all .pwc files from all child directories in my git repository and then ignore them for any future commit?

[Assistant]
Plenty of ways to remove them:
git ls-files | grep '\.pwc$' | xargs git rm

find . -name *.pwc | xargs git rm

Note: If you haven't committed them, just use rm, not git rm.
To ignore them in the future, simply add *.pwc to the .gitignore. (If you don't have one, create a file named .gitignore at the top level of your repository, and just add a single line saying "*.pwc")


[System] You are a helpful assistant.

[User] git-log - Show commit logs  default

[Assistant]
Is a synonym for zebra . This may change to a more sensible mode
in the future.


[System] You are a helpful assistant.

[User]
How to use git branch with Android Studio
I am new to git. I have a very simple scenario for using git. I had my first release written with Android Studio. Now I want to work with some new features. What I did so far:

enabled the VCS in my Android Studio
created a local repository for my project from Android Studio
pushed my local repository to my Bitbucket remote repository ($git push -u origin master)

Now I am confused for the next step: create a feature branch. Should I create a branch in the local repository:
$ git branch --track feature1 origin/master

or should I create a new branch from the Bitbucket web portal, and clone the new branch?
I also want to know how I can switch branches with Android Studio? For example, switch from feature branch to master branch to work on some hotfix. Do I need to use the Bitbucket plugin to checkout the project very time from the remote repository every time I switch branches or I can hot switch it inside Android Studio?
Thanks!

[Assistant]
You should be able to do this directly from Android studio.
The easiest way is going to the bottom right corner of the Android Studio window where you should see the text "Git: branch name", in your case it should say "Git: master". Click on it and it will show a small menu consisting of the different branches available both locally and remotely, also there should be an option "+ New Branch" which will create a new branch for you and switch you to it.
You should then be able to change some code, commit it and push it to remote. Merging and checking out branches can also be done from that same menu. The same thing can also be done from the menubar option "VCS"


[System] You are a helpful assistant.

[User] git-ls-files - Show information about files in the index and the working tree  --sparse

[Assistant]
If the index is sparse, show the sparse directories without expanding
to the contained files. Sparse directories will be shown with a
trailing slash, such as "x/" for a sparse directory "x".


[System] You are a helpful assistant.

[User]
Is there a program like GITLAB written in PHP? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

 Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

Closed 10 years ago.

                        Improve this question

I'm looking for a program to run on my company's intranet to help sort out projects. GitHub it out of the question because I'm not going to pay money for private repos, but I love the way GitHub looks.
GITLAB is also nice and I would have chosen it except my servers are running PHP not Ruby. Is there a solution?

[Assistant]
There are some projects for PHP but all are not that actively developed compared to GitLab

gitphp - http://gitphp.org/projects/gitphp/wiki ... kind-of dislike that the project's website is based on Redmine ... 18 contributors - only 1 seems to be active http://www.ohloh.net/p/gitphp/contributors
mtrack - http://mtrack.wezfurlong.org/features.html ... 9 contributors - 2 active http://www.ohloh.net/p/mtrack/contributors
Redmine-Php seems to be dead (homepage is down ... git-repo not updated since 1 year)
traq also seems interesting ... http://traq.io/

And of course, many more I don't know of :)
Feel free to search for similar projects on https://www.ohloh.net for trac, redmine, gitlab and other known systems.
In my opinion mtrack seems like the most promising as it provides functions like forking projects in the UI.


[System] You are a helpful assistant.

[User]
How can I save username and password in Git?
I want to use a push and pull automatically in Git Extensions, Sourcetree or any other Git GUI without entering my username and password in a prompt, every time.
So how can I save my credentials in Git?

[Assistant]
Attention:
This method saves the credentials in plaintext on your PC's disk. Everyone on your computer can access it, e.g. malicious NPM modules.
Run:
git config --global credential.helper store

then:
git pull

provide a username and password and those details will then be remembered later. The credentials are stored in a file on the disk, with the disk permissions of "just user readable/writable" but still in plaintext.
If you want to change the password later:
git pull

Will fail, because the password is incorrect, git then removes the offending user+password from the ~/.git-credentials file, so now re-run:
git pull

to provide a new password so it works as earlier.


[System] You are a helpful assistant.

[User] git-for-each-ref - Output information on each ref  --exclude=<pattern>

[Assistant]
If one or more patterns are given, only refs which do not match
any excluded pattern(s) are shown. Matching is done using the
same rules as <pattern> above.


[System] You are a helpful assistant.

[User]
Tracking changes to hooks in .git/hooks
Is there a way to track git hook changes?  I have three hooks that only show up on my machine, not when my other developers fetch.  Trying to git add doesn't work.

[Assistant]
http://benjamin-meyer.blogspot.com/2008/10/git-hooks.html

Files in the .git/hooks directory are not part of the repository and so they are not tracked. A workaround is to have a git_hooks directory at the top of your repository like done in Arora and symlink .git/hooks to git_hooks whenever you clone. This way the hooks will be part of the project, under revision control and accessible to everyone.


[System] You are a helpful assistant.

[User]
Why does "git push main" work on GitHub when "git push master" does not? Also what is difference between "Main branch" and "Master branch"?
I tried git push on my master branch, but it just shows that I have a new pull request. When I click on the new pull request, it takes me to the comparing changes view, but doesn't show any option to add those changes into repository. It only shows the changes I made:

When I entered the command
git push origin main

all files where added to my repository.
but when I do
git push origin master

it doesn't work.
Why is that? I heard they are replacing master with main. So in the future are they going to remove master?

[Assistant]
From the ZDNet article, GitHub to replace "master" with alternative term to avoid slavery references:

GitHub is working on replacing the term "master" on its service with a neutral term like "main" to avoid any unnecessary references to slavery,

About renaming your branch from master to main, there are a lot of guidelines. For example:
git branch -m master main \
git push -u origin main \
git remote set-head origin main


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  --no-renames

[Assistant]
Turn off rename detection, even when the configuration
file gives the default to do so.


[System] You are a helpful assistant.

[User] git-diff-index - Compare a tree to the working tree or index  --indent-heuristic

[Assistant]
Enable the heuristic that shifts diff hunk boundaries to make patches
easier to read. This is the default.


[System] You are a helpful assistant.

[User]
How to fix "corrupted" interactive rebase?
I managed to create a little mess in my local git repository. I was trying to fix a broken commit by using the following instructions. Before running the "git commit --amend" (and after the git rebase --interactive) I decided that my changes were incorrect and so I executed "git reset HEAD --hard". Not a good idea, I tell you.
Now the interactive rebase seems to be "stuck". Git shows the current branch as (|REBASE-m). Every command (cd .., ls, git rebase...) inside my repository gives the following error:

cat: .git/rebase-merge/head-name: No such file or directory

Here's how git rebase --abort looks like:
$ git rebase --abort
cat: c:/_work/project/src/git/.git/rebase-merge/quiet: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/head-name: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/orig-head: No such file or directory
HEAD is now at 4c737fb Revert "Modified file names"
rm: cannot remove `c:/_work/project/src/git/.git/rebase-merge/done': Permission denied
rm: cannot remove directory `c:/_work/project/src/git/.git/rebase-merge': Directory
not empty
cat: .git/rebase-merge/head-name: No such file or directory

Here's the result of git rebase --continue:
$ git rebase --continue
cat: c:/_work/project/src/git/.git/rebase-merge/prev_head: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/end: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/msgnum: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/onto: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/quiet: No such file or directory
prev_head must be defined
cat: .git/rebase-merge/head-name: No such file or directory

Any ideas? I would like to reset the situation back to the state it was before I started my well-thought rebase operation.
Here's how git log --oneline shows the situation:
4c737fb Revert "Modified file names"
247ac02 Modified file names
33141e6 Message modifications
10a4a04 Modified db script

And this is fine.
I'm using msysgit v1.7.0.2.

[Assistant]
I got stuck in this. I created the head-name file, and then I ran into another error saying it couldn't find the onto file, so I created that file. Then I got another error saying could not read '.git/rebase-apply/onto': No such file or directory.
So I looked at the git documentation for rebasing and found another command:
git rebase --quit

This set me back on my branch with no changes, and I could start my rebase over again, good as new.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  git-for-each-repo

[Assistant] Run a Git command on a list of repositories


[System] You are a helpful assistant.

[User] git-rev-parse - Pick out and massage parameters  --resolve-git-dir <path>

[Assistant]
Check if <path> is a valid repository or a gitfile that
points at a valid repository, and print the location of the
repository.  If <path> is a gitfile then the resolved path
to the real repository is printed.


[System] You are a helpful assistant.

[User] git-notes - Add or inspect object notes

[Assistant]
DISCUSSION Commit notes are blobs containing extra information about an object
(usually information to supplement a commit’s message).  These blobs
are taken from notes refs.  A notes ref is usually a branch which
contains "files" whose paths are the object names for the objects
they describe, with some directory separators included for performance
reasons [ 1 ] . Every notes change creates a new commit at the specified notes ref.
You can therefore inspect the history of the notes by invoking, e.g., git log -p notes/commits .  Currently the commit message only records
which operation triggered the update, and the commit authorship is
determined according to the usual rules (see git-commit ).
These details may change in the future. It is also permitted for a notes ref to point directly to a tree
object, in which case the history of the notes can be read with git log -p -g <refname> .


[System] You are a helpful assistant.

[User]
How to preview git-pull?
Is it even possible?
Basically, there's a remote repository from which I pull using just:
git pull

Now, I'd like to preview what this pull would change (a diff) without touching anything on my side. The reason is that thing I'm pulling might not be "good" and I want someone else to fix it before making my repository "dirty".

[Assistant]
After doing a git fetch, do a git log HEAD..origin/master to show the log entries between your last common commit and the origin's master branch. To show the diffs, use either git log -p HEAD..origin/master to show each patch, or git diff HEAD...origin/master (three dots not two) to show a single diff.
There normally isn't any need to undo a fetch, because doing a fetch only updates the remote branches and none of your branches. If you're not prepared to do a pull and merge in all the remote commits, you can use git cherry-pick to accept only the specific remote commits you want. Later, when you're ready to get everything, a git pull will merge in the rest of the commits.
Update: I'm not entirely sure why you want to avoid the use of git fetch. All git fetch does is update your local copy of the remote branches. This local copy doesn't have anything to do with any of your branches, and it doesn't have anything to do with uncommitted local changes. I have heard of people who run git fetch in a cron job because it's so safe. (I wouldn't normally recommend doing that, though.)


[System] You are a helpful assistant.

[User]
Partial clone with Git and Mercurial
Is it possible to clone only one branch (or from a given commit) in Git and Mercurial? I mean, I want to clone a central repo but since it's huge I'd like to only get part of it and still be able to contribute back my changes. Is it possible? Like, I only want from Tag 130 onwards or something like that?
If so, how?

[Assistant]
In Git land you are talking about three different types of partial clones:

shallow clones: I want history from revision point X onward.
Use git clone --depth <n> <url> for that, but please remember that shallow clones are somewhat limited in interacting with other repositories.  You would be able to generate patches and send them via email.
partial clone by filepath: I want all revision history history in some directory /path.
Not possible in Git.  With modern Git though you can have sparse checkout, i.e. you have whole history but you check out (have in working area) only subset of all files.
cloning only selected branch: I want to clone only one branch (or selected subset of branches).
Possible, and
before git 1.7.10 not simple: you would need to do what clone does manually, i.e. git init [<directory>], then git remote add origin <url>, edit .git/config replacing * in remote.origin.fetch by requested branch (probably 'master'), then git fetch .
as of git 1.7.10 git clone offers the --single-branch option which seems like it was added just for this purpose, and seems pretty easy.
Note however that because branches usually share most of their history, the gain from cloning only a subset of branches might be smaller than you think.

You can also do a shallow clone of only selected subset of branches.
If you know how people will want to break things down by filepath (multiple projects in the same repository) you can use submodules (sort of like svn:externals) to pre-split the repo into separately cloneable portions.


[System] You are a helpful assistant.

[User] git-shortlog - Summarize git log output  --date=<format>

[Assistant]
Show dates formatted according to the given date string. (See
the --date option in the "Commit Formatting" section of git-log ). Useful with --group=format:<format> .


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  gui.matchTrackingBranch

[Assistant]
Determines if new branches created with git-gui should
default to tracking remote branches with matching names or
not. Default: "false".


[System] You are a helpful assistant.

[User]
Should I commit .gitignore file? [duplicate]

This question already has answers here:

Should you commit .gitignore into the Git repos?

                                (6 answers)

Closed 10 years ago.

After reading  proper section of GitHub Help I got completely lost. It says:

This file can be committed into the repository, thus sharing the rule list with any other users that clone the repository.

Up until now, people I've been talking to about Git were telling me that ".gitingore file must be committed or else its rules won't work!"
Every Git begginer's question: "Why .gitignore rules are not applied?"
Could be answered with a simple: "Did you commit it?".
And now, here comes the GitHub Help saying, that this file can be commited, but it isn't necessary

[Assistant]
Yes, you can track the .gitignore file, but you do not have to.
The main reason of having this file into repository is to have everyone working on the project, ignoring same files and folders.
Also see this: Should you commit .gitignore into the Git repos?


[System] You are a helpful assistant.

[User]
Remove a modified file from pull request
I have 3 modified files (no new files) in a pull request at the moment.
I would like to remove one of those files from the pull request, so that the pull request only contains changes to two files and leaves the third in its original, untouched state.
I have tried a couple things (checking out the original version of the file, etc...) but it still shows as a changed file in the PR.
Is there a solution to this?

[Assistant]
Switch to the branch from which you created the pull request:
$ git checkout pull-request-branch

Overwrite the modified file(s) with the file in another branch, let's consider it's master:
git checkout origin/master -- src/main/java/HelloWorld.java

Commit and push it to the remote:
git commit -m "Removed a modified file from pull request"
git push origin pull-request-branch

Reference:
See git checkout docs:
git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <pathspec>…

Overwrite the contents of the files that match the pathspec. When the <tree-ish> (most often a commit) is not given, overwrite working tree with the contents in the index. When the <tree-ish> is given, overwrite both the index and the working tree with the contents at the <tree-ish>.

Anything within [] is optional. In our case, we want to overwrite   items identified by a specific pathspec with its respective content at a different branch/commit/tag


[System] You are a helpful assistant.

[User] git-format-patch - Prepare patches for e-mail submission  -l<num>

[Assistant]
The -M and -C options involve some preliminary steps that
can detect subsets of renames/copies cheaply, followed by an
exhaustive fallback portion that compares all remaining
unpaired destinations to all relevant sources.  (For renames,
only remaining unpaired sources are relevant; for copies, all
original sources are relevant.)  For N sources and
destinations, this exhaustive check is O(N^2).  This option
prevents the exhaustive portion of rename/copy detection from
running if the number of source/destination files involved
exceeds the specified number.  Defaults to diff.renameLimit.
Note that a value of 0 is treated as unlimited.


[System] You are a helpful assistant.

[User] git-shortlog - Summarize git log output  --full-history without parent rewriting

[Assistant]
This mode differs from the default in one point: always follow
all parents of a merge, even if it is TREESAME to one of them.
Even if more than one side of the merge has commits that are
included, this does not imply that the merge itself is!  In
the example, we get I  A  B  N  D  O  P  Q M was excluded because it is TREESAME to both parents. E , C and B were all walked, but only B was !TREESAME, so the others
do not appear. Note that without parent rewriting, it is not really possible to talk
about the parent/child relationships between the commits, so we show
them disconnected.


[System] You are a helpful assistant.

[User]
How to open google chrome from terminal?
I'm trying to create an alias that opens google chrome to localhost. Port 80 in this case.
I'd also really like to be able to be in any git directory and have it open that specific project in the browser, but I'm not sure if that's even possible.

How do I open google chrome from the terminal?
What alias could I use to open the current git project in the browser?

More Details:

My localhost is set to port 80.
I store my git repositories in ~/Sites/ - meaning if I wanted to view any project in the browser it would be found here: http://localhost/FILENAME

Thank You

[Assistant]
From the macOS Terminal, use open with the -a flag and give the name of the app you want to open. In this case "Google Chrome". You may pass it a file or URL you want it to open with.
open -a "Google Chrome" index.html


[System] You are a helpful assistant.

[User] git-log - Show commit logs  %gN

[Assistant] reflog identity name (respecting .mailmap, see git-shortlog or git-blame )


[System] You are a helpful assistant.

[User]
Where is git.exe located?
I have PyCharm and I am looking around trying to find git.exe to set it up with my repo.
What is the PATH to git.exe?

[Assistant]
If you're using GitHub for Windows, git.exe may not be in your PATH, but you may find it in a location like: C:\Users\<username>\AppData\Local\GitHub\PortableGit_<numbersandletters>\bin\git.exe
That's the situation for me, in Windows 7 + version 1.0 of GitHub for Windows.
In Windows 10 it appears to be in:
C:\Users\<username>\AppData\Local\GitHub\PortableGit_<numbersandletters>\cmd\git.exe
( \cmd versus \bin)
From GitHub Desktop 1.1
The UI is different and the Git path now is in:
C:\Users\<username>\AppData\Local\GitHubDesktop\app-<appversion>\resources\app\git\cmd\git.exe
PS: AppData is a hidden folder by default.


[System] You are a helpful assistant.

[User] git-reset - Reset current HEAD to the specified state  --merge

[Assistant]
Resets the index and updates the files in the working tree that are
different between <commit> and HEAD , but keeps those which are
different between the index and working tree (i.e. which have changes
which have not been added).
If a file that is different between <commit> and the index has
unstaged changes, reset is aborted. In other words, --merge does something like a git read-tree -u -m <commit> ,
but carries forward unmerged index entries.


[System] You are a helpful assistant.

[User]
Git: move a commit "on top"
Let's say in master I have a feature disabled.
I work on that feature on branch feature, so I have a special commit $ there that just enables that feature.
Now I want to merge the changes I did in feature into master, but keep the enabling commit out. So it's like
main:    A--B--X--Y
feature: A--B--$--C--D

So let's say I want to do it, by moving the $ commit on top of feature:
new feature: A--B--C--D--$

How would I go about doing that?

[Assistant] git rebase -i B, and then move $ to the end of the list that shows up in your editor.  It will start out as the first line in the file that opens.  You could also just delete that line entirely, which will just drop that commit out of your branch's history.


[System] You are a helpful assistant.

[User]
Git Commit Messages: 50/72 Formatting
Tim Pope argues for a particular Git commit message style in his blog post:
http://www.tpope.net/node/106.
Here is a quick summary of what he recommends:

First line is 50 characters or less.
Then a blank line.
Remaining text should be wrapped at 72 characters.

His blog post gives the rationale for these recommendations (which I will call “50/72 formatting” for brevity):

In practice, some tools treat the first line as a subject line and the second paragraph as a body (similar to email).
git log does not handle wrapping, so it is hard to read if lines are too long.
git format-patch --stdout converts commits to email — so to play nice it helps if your commits are already wrapped nicely.

A point I would like to add that I think Tim would agree with:

The act of summarizing your commit is a good practice inherently in any version control system. It helps others (or a later you) find relevant commits more quickly.

So, I have a couple of angles to my question:

What chunk (roughly) of the “thought leaders” or “experienced users” of Git embrace the 50/72 formatting style? I ask this because sometime newer users don’t know or don’t care about community practices.
For those that don’t use this formatting, is there a principled reason for using a different formatting style? (Please note that I’m looking for an argument on the merits, not “I’ve never heard of it” or “I don’t care.”)
Empirically speaking, what percentage of Git repositories embrace this style? (In case someone wants to do an analysis on GitHub repositories… hint, hint.)

My point here is not to recommend the 50/72 style or shoot down other styles. (To be open about it, I do prefer it, but I am open to other ideas.) I just want to get the rationale for why people like or oppose various Git commit message styles. (Feel free to bring up points that haven’t been mentioned, too.)

[Assistant]
Regarding the “summary” line (the 50 in your formula), the Linux kernel documentation has this to say:
For these reasons, the "summary" must be no more than 70-75
characters, and it must describe both what the patch changes, as well
as why the patch might be necessary.  It is challenging to be both
succinct and descriptive, but that is what a well-written summary
should do.

That said, it seems like kernel maintainers do indeed try to keep things around 50. Here’s a histogram of the lengths of the summary lines in the git log for the kernel:
 (view full-sized)
There is a smattering of commits that have summary lines that are longer (some much longer) than this plot can hold without making the interesting part look like one single line. (There’s probably some fancy statistical technique for incorporating that data here but oh well… :-)
If you want to see the raw lengths:
cd /path/to/repo
git shortlog  | grep -e '^      ' | sed 's/[[:space:]]\+\(.*\)$/\1/' | awk '{print length($0)}'

or a text-based histogram:
cd /path/to/repo
git shortlog  | grep -e '^      ' | sed 's/[[:space:]]\+\(.*\)$/\1/' | awk '{lens[length($0)]++;} END {for (len in lens) print len, lens[len] }' | sort -n


[System] You are a helpful assistant.

[User] git-blame - Show what revision and author last modified each line of a file  --incremental

[Assistant]
Show the result incrementally in a format designed for
machine consumption.


[System] You are a helpful assistant.

[User]
git merge with renamed files
I have a large website that I am moving into a new framework and in the process adding git. The current site doesn't have any version control on it.
I started by copying the site into a new git repository. I made a new branch and made all of the changes that were needed to make it work with the new framework. One of those steps was changing the file extension of all of the pages.
Now in the time that I have been working on the new site changes have been made to files on the old site. So I switched to master and copied all of those changes in.
The problem is when I merge the branch with the new framework back onto master there is a conflict on every file that was changed on the master branch.
I wouldn't be to worried about it but there are a couple of hundred files with changes. I have tried git rebase and git rebase --merge with no luck.
How can I merge these 2 branches without dealing with every file?

[Assistant]
Since git 1.7.4, you can specify the rename threshold for merge as git merge -X rename-threshold=25 in order to control that a similarity of 25% is already enough to consider two files rename candidates. This, depending on the case together with -X ignore-space-change may make rename detection more reliable.
However, I wanted to have more direct control and was cooking up a related script the last days. Maybe it helps - let me know.
https://gist.github.com/894374


[System] You are a helpful assistant.

[User]
git: why can't I delete my branch after a squash merge?
I have a git repo with mainline (equivalent to master) and some local feature branches.  For example:
$ git branch
* mainline
  feature1
  feature2
  feature3

When I do the following, I am able to squash merge all of my edits in a feature branch into one commit to mainline:
$ git checkout mainline
$ git pull
$ git checkout feature1
$ git rebase mainline
$ git checkout mainline
$ git merge --squash feature1
$ git commit
$ git push

My question is, at this point, when I try to delete the feature1 branch, it tells me it is not fully merged:
$ git branch -d feature1
error: The branch 'feature1' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature1'.

What causes this error? I thought git merge --squash feature1 merged feature1 into mainline.

[Assistant]
This happens because Git doesn't know that the squash merge is "equivalent to" the various branch-specific commits.  You must forcibly delete the branch, with git branch -D instead of git branch -d.
(The rest of this is merely about why this is the case.)
Draw the commit graph
Let's draw (part of) the commit graph (this step is appropriate for so many things in Git...).  In fact, let's step back one more step, so that we start before your git rebase, with something like this:
...--o--o--o     <-- mainline
      \
       A--B--C   <-- feature1

A branch name, like mainline or feature1, points only to one specific commit.  That commit points back (leftward) to a previous commit, and so on, and it's these backward pointers that form the actual branches.
The top row of commits, all just called o here, are kind of boring, so we didn't give them letter-names.  The bottom row of commits, A-B-C, are only on branch feature1.  C is the newest such commit; it leads back to B, which leads back to A, which leads back to one of the boring o commits.  (As an aside: the leftmost o commit, along with all earlier commits in the ... section, is on both branches.)
When you ran git rebase, the three A-B-C commits were copied to new commits appended to the tip of mainline, giving us:
...--o--o--o            <-- mainline
      \     \
       \     A'-B'-C'   <-- feature1
        \
         A--B--C       [old feature1, now abandoned]

The new A'-B'-C' commits are mostly the same as the original three, but they are moved in the graph.  (Note that all three boring o commits are on both branches now.)  Abandoning the original three means that Git usually doesn't have to compare the copies to the originals.  (If the originals had been reachable by some other name—a branch that appended to the old feature1, for instance—Git can figure this out, at least in most cases.  The precise details of how Git figures this out are not particularly important here.)
Anyway, now you go on to run git checkout mainline; git merge --squash feature1.  This makes one new commit that is a "squash copy" of the three—or however many—commits that are on feature1.  I will stop drawing the old abandoned ones, and call the new squash-commit S for Squash:
...--o--o--o--S         <-- mainline
            \
             A'-B'-C'   <-- feature1

"Delete safety" is determined entirely by commit history
When you ask Git to delete feature1, it performs a safety check: "is feature1 merged into mainline?"  This "is merged into" test is based purely on the graph connectivity.  The name mainline points to commit S; commit S points back to the first boring o commit, which leads back to more boring o commits.  Commit C', the tip of feature1, is not reachable from S: we're not allowed to move rightward, only leftward.
Contrast this with making a "normal" merge M:
...--o--o--o---------M   <-- mainline
            \       /
             A'-B'-C'    <-- feature1

Using the same test—"is the tip commit of feature1 reachable from the tip commit of mainline?"—the answer is now yes, because commit M has a down-and-left link to commit C'.  (Commit C' is, in Git internal parlance, the second parent of merge commit M.)
Since squash merges are not actually merges, though, there is no connection from S back to C'.
Again, Git doesn't even try to see if S is "the same as" A', B', or C'.  If it did, though, it would say "not the same", because S is only the same as the sum of all three commits.  The only way to get S to match the squashed commits is to have only one such commit (and in this case, there's no need to squash in the first place).


[System] You are a helpful assistant.

[User]
How to list branches that contain a given commit?
How can I query git to find out which branches contain a given commit? gitk will usually list the branches, unless there are too many, in which case it just says "many (38)" or something like that. I need to know the full list, or at least whether certain branches contain the commit.

[Assistant]
From the git-branch manual page:
 git branch --contains <commit>

Only list branches which contain the specified commit (HEAD if not specified). Implies --list.

 git branch -r --contains <commit>

Lists remote tracking branches as well (as mentioned in user3941992's answer below) that is "local branches that have a direct relationship to a remote branch".

As noted by Carl Walsh, this applies only to the default refspec
fetch = +refs/heads/*:refs/remotes/origin/*

If you need to include other ref namespace (pull request, Gerrit, ...), you need to add that new refspec, and fetch again:
git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"
git fetch
git branch -r --contains <commit>

See also this git ready article.

The --contains tag will figure out if a certain commit has been brought in yet into your branch. Perhaps you’ve got a commit SHA from a patch you thought you had applied, or you just want to check if commit for your favorite open source project that reduces memory usage by 75% is in yet.

$ git log -1 tests
commit d590f2ac0635ec0053c4a7377bd929943d475297
Author: Nick Quaranto <[email protected]>
Date:   Wed Apr 1 20:38:59 2009 -0400

    Green all around, finally.

$ git branch --contains d590f2
  tests
* master

Note: if the commit is on a remote tracking branch, add the -a option.
(as MichielB comments below)
git branch -a --contains <commit>

MatrixFrog comments that it only shows which branches contain that exact commit.
If you want to know which branches contain an "equivalent" commit (i.e. which branches have cherry-picked that commit) that's git cherry:

Because git cherry compares the changeset rather than the commit id (sha1), you can use git cherry to find out if a commit you made locally has been applied <upstream> under a different commit id.
For example, this will happen if you’re feeding patches <upstream> via email rather than pushing or pulling commits directly.

           __*__*__*__*__> <upstream>
          /
fork-point
          \__+__+__-__+__+__-__+__> <head>

(Here, the commits marked '-' wouldn't show up with git cherry, meaning they are already present in <upstream>.)


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  -S<string>

[Assistant]
Look for differences that change the number of occurrences of
the specified string (i.e. addition/deletion) in a file.
Intended for the scripter’s use. It is useful when you’re looking for an exact block of code (like a
struct), and want to know the history of that block since it first
came into being: use the feature iteratively to feed the interesting
block in the preimage back into -S , and keep going until you get the
very first version of the block. Binary files are searched as well.


[System] You are a helpful assistant.

[User]
Difference between "git checkout <filename>" and "git checkout -- <filename>"
http://norbauer.com/notebooks/code/notes/git-revert-reset-a-single-file
I have found a post.
But still don't know what is the difference between

git checkout <filename>
git checkout -- <filename>

In what situation I should use first one and second one respectively?

[Assistant]
The special "option" -- means "treat every argument after this point as a file name, no matter what it looks like."  This is not Git-specific, it's a general Unix command line convention.  Normally you use it to clarify that an argument is a file name rather than an option, e.g.
rm -f      # does nothing
rm -- -f   # deletes a file named "-f"

git checkout1 also takes -- to mean that subsequent arguments are not its optional "treeish" parameter specifying which commit you want.
So in this context it's safe to use -- always, but you need it when the file you want to revert has a name that begins with -, or is the same as the name of a branch.  Some examples for branch/file disambiguation:
git checkout README     # would normally discard uncommitted changes
                        # to the _file_ "README"

git checkout master     # would normally switch the working copy to
                        # the _branch_ "master"

git checkout -- master  # discard uncommitted changes to the _file_ "master"

and option/file disambiguation:
git checkout -p -- README  # interactively discard uncommitted changes
                           # to the file "README"

git checkout -- -p README  # unconditionally discard all uncommitted
                           # changes to the files "-p" and "README"

I'm not sure what you do if you have a branch whose name begins with -.  Perhaps don't do that in the first place.

1 in this mode; "checkout" can do several other things as well.  I have never understood why git chose to implement "discard uncommitted changes" as a mode of the "checkout" subcommand, rather than "revert" like most other VCSes, or "reset" which I think might make more sense in git's own terms.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  GIT_CONFIG_COUNT  GIT_CONFIG_KEY_<n>  GIT_CONFIG_VALUE_<n>

[Assistant]
If GIT_CONFIG_COUNT is set to a positive number, all environment pairs
GIT_CONFIG_KEY_<n> and GIT_CONFIG_VALUE_<n> up to that number will be
added to the process’s runtime configuration. The config pairs are
zero-indexed. Any missing key or value is treated as an error. An empty
GIT_CONFIG_COUNT is treated the same as GIT_CONFIG_COUNT=0, namely no
pairs are processed. These environment variables will override values
in configuration files, but will be overridden by any explicit options
passed via git -c . This is useful for cases where you want to spawn multiple git commands
with a common configuration but cannot depend on a configuration file,
for example when writing scripts.


[System] You are a helpful assistant.

[User]
How can I make a second fork of a GitHub project?

I want to fork a github project to fix a couple of issues and then send a pull request.
The problem I'm running into is that I've already forked the project to adapt it for another user base.
Is it possible to create a second fork? If so, how?
When I try to fork now it just takes me to the previously created fork.

[Assistant]
There is no way to have two forks of the same GitHub project unless you use two different GitHub accounts.
So:

Create a separate GitHub account (and verify the email)
Fork the
project
Invite your main GitHub account as a "Collaborator" (from
the settings)

You may need to add the extra step of creating an organization with the new GitHub account and inviting your main github account as an owner of the organization (also make sure your new fork is in that new organization). This will let you do things like deploy automatically to a Heroku app that is connected to your main GitHub account.
Why can't we just have multiple forks???


[System] You are a helpful assistant.

[User]
Git pull all branches from a remote repository
How do I pull all of the remote branches to my own repository?
If I type:
git branch -a

I get a long list of branches, but if I type:
git branch

I see only two of them.
How do I pull all branches into my local list?
I know I can do:
git checkout --track origin/branch-name

but that pulls and checks out only one branch at a time. Is there a way to get it all done at once without that whole tedious work of running git checkout --track origin/branch-name over and over and over again?

PS: I tried the following commands, but none of them made remote branches appear in my git branch list:
git fetch --all
git remote update
git pull --all

[Assistant]
Read e.g. this explanation http://git-scm.com/book/en/Git-Branching-Remote-Branches
First let's clarify some git terminology:

fetch: getting contents (or updates) from a remote repo
pull: fetch (as above) and merge in one step

The original poster did not mention merging, so I might guess in proper git terminology
he might even have wanted to ask "git fetch all branches from remote repository"
If you see the branches in git branch -a then you have already fetched them.
You can verify this by giving the command git show remotes/origin/some-branch:some-file
Or can do e.g. git diff remotes/origin/some-branch master
You can even check them out git checkout remotes/origin/some-branch
(To be sure you can remove the network cable and you will see that the commands work without contacting the remote repo.)
The branches named remotes/... are called remote branches, but they are already fetched to your repo. They are read-only, you cannot modify them (that's why a message appears when checking out). Although they reflect the state of a remote repo at the time of the last fetch or pull operation they are in fact stored locally.
If you do git checkout some-branch and some-branch does not yet exist but remotes/origin/some-branch exists, git will create a tracking branch called some-branch for you (1). Again this is a local operation, all data has been fetched before (or if you have not recently fetched, you will start working on an obsolete version). Originally the contents of the tracking branch is identical to its remote branch. However, the tracking branch can be modified by you locally.
The git working area contains the state of one branch at time. So your question about checking out all remote branches at once does not really make sense in the context of git. You can check out them one after each other. But each time you check out the next one, the previous one will disappear from the working area. Of course this operation can be scripted as shown in Track all remote git branches as local branches But what is the point of scripting a mass operation if only its last step is what remains?
So could the question be caused by a misunderstanding, assuming that remote branches would be only stored remotely, but not locally and you just wanted to make sure that you have everything local?  If you really want to have more than one branch checked out at a time you can clone your repo locally and checkout different branches into different work areas. (2)
Shortly: If you want to be sure that you have all data available locally that is in the
remote repo just use git fetch [repo]. Unless you have tweaked with your configuration this will fetch all branches, i.e. updating existing remote branches and also creating new remote ones if applicable.
(1) This is true in simple standard cases. In more complicated cases with more than 1 remote or manually configured remotes you might need the --track option to specify exactly what you want.
(2) There is a new feature git worktree for this use case. However as of early 2018 it is still marked experimental


[System] You are a helpful assistant.

[User]
Is there a way to reduce the size of the Git folder?
It seems like my project is getting bigger and bigger with every Git commit/push. Is there a way to clean up my Git folder?

[Assistant]
I'm not sure what you want. First of all, of course each time you commit/push the directory is going to get a little larger, since it has to store each of those additional commits.
However, probably you want git gc which will "cleanup unnecessary files and optimize the local repository" (manual page).
Another possibly relevant command is git clean which will delete untracked files from your tree (manual page).


[System] You are a helpful assistant.

[User]
Adding self-signed SSL certificate without disabling authority-signed ones

I have a corporate git server working through https using self-signed certificate. The local clone contains two remotes — the origin pointing to that server, and another pointing to github.
By default pulling from the origin fails:
$ git pull
fatal: unable to access 'https://[email protected]/git/fizzbuzz.git/': SSL certificate problem: self signed certificate

The github remote works fine.
There are two often-suggested solutions:
git config http.sslVerify false

which is a bad idea, and the one suggested at configure Git to accept a particular self-signed server certificate for a particular https remote:
git config http.sslCAInfo <downloaded certificate>.pem

which fixes pulling from origin, but break the github remote:
$ git pull github
fatal: unable to access 'https://github.com/user/fizzbuzz.git/': SSL certificate problem: unable to get local issuer certificate

How to make pulling from the corporate server work without breaking pulling from github?

[Assistant]
If you are using Git 1.8.5+ (August 2013), you can specify http directives per URL(!).
In your case:
git config --global http."https://code.example.com/".sslVerify false
#
# or, if not on default 443 port:
#
git config --global http."https://code.example.com:<aPort>/".sslVerify false

That would disable SSL verification only for code.example.com, not for other URLs.
Or:
git config --global http."https://code.example.com/".sslCAInfo <downloaded certificate>.pem

Same idea: sslCAInfo would point to <downloaded certificate>.pem only for code.example.com URLs.
It is possible to add your certificate in the Git system certificate store, which, with git-for-windows, would be in C:\path\to\PortableGit-2.6.1-64-bit\usr\ssl\certs\ca-bundle.crt.
It isn't the best practice, though, unless you have to distribute a Git distro with internal certificates in it.


[System] You are a helpful assistant.

[User]
How can I find all public comments for a Github user?

Until recently I was able to find all my public comments using a link on my profile page. I was using this functionality to keep track of all issues where I have commented, but not contributed anything. It was under a section called "Public Activity".
This function seems to have been removed. I can not find anything about it on the help page about profiles.
Does anybody have any information on when and why this was removed?

[Assistant]
You can do this with an advanced search query. In the top nav search field, enter is:issue commenter:username. This will return a list of all issues and pull requests where the user has commented. You can then click on each issue or pull request to view the individual comments.
To search within a specific repository: repo-name commenter:username.
To view your own latest comments across GitHub, use:
is:issue commenter:@me


[System] You are a helpful assistant.

[User]
Multiple Routers and Services on the same container with traefik 2

I'm currently trying to get traefik to use multiple routers and services on a single container, which isn't working and i don't know if this is intended at all.
Why?
Specificly i'm using an gitlab omnibus container and wanted to use / access multiple services inside the omnibus container since gitlab is providing not only "the gitlab website" with it.
What did i try?
I simply tried adding another router to my docker compose file via labels
This is what i have:
labels:
  - "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
  - "traefik.http.services.gitlab.loadbalancer.server.port=80"

This is what i want:
labels:
  - "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
  - "traefik.http.services.gitlab.loadbalancer.server.port=80"
  - "traefik.http.routers.registry.rule=Host(`registry.gitlab.example.com`)"
  - "traefik.http.services.registry.loadbalancer.server.port=5000"

This doesn't work since traefik probably getting confused with what to route to which service and i couldn't find a mechanism that tells traefik exactly which router goes to which service in a case like this.
Is this even possible or am i just missing a little bit of traefik magic?

[Assistant]
I found the solution to my Question.
There's indeed a little bit i missed:

traefik.http.routers.myRouter.service=myService

With this Label i can point a Router to a specific Service and should be able to add multiple services to one container:
labels:
  - "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
  - "traefik.http.routers.gitlab.service=gitlab"
  - "traefik.http.services.gitlab.loadbalancer.server.port=80"
  - "traefik.http.routers.registry.rule=Host(`registry.gitlab.example.com`)"
  - "traefik.http.routers.registry.service=registry"
  - "traefik.http.services.registry.loadbalancer.server.port=5000"

Here each router is pointed to a specific service explicitly which normally happens implicitly.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  GIT_NO_LAZY_FETCH

[Assistant]
Setting this Boolean environment variable to true tells Git
not to lazily fetch missing objects from the promisor remote
on demand.


[System] You are a helpful assistant.

[User]
How to restrict access to the master branch in Git
I have a single repository in which I have two user groups:

Administrators
HTML/UI Developers

I do not wish to give read/write access of my master branch to my HTML developers as they do not need to work on it and should not be misusing the core code.
Though they need to work on their own branch ui-developers. How do I do this on Git?
P.S.: I am using Bitbucket

I had posted this question when I was extremely new to coding and Git. After two years of experience, I now know that Git doesn't allow to restrict READ access for any particular branch. But services like Bitbucket, GitLab, and GitHub allow you to put write and merge restrictions to branches.
Also, I shifted to GitLab six months back :)

[Assistant]
Git itself does not have such feature, but many hosting providers do. This is generally known as branch protection. There is no way to prevent read access as far as I know.
Using Bitbucket
Bitbucket allows a lot of customization for the actions to prevent by branch protection. To protect a branch:

Go to a repository in a project.

Choose Settings → Branch permissions.

Click Add permission.

In the Branches field, select either Branch name, Branch pattern, or Branching model.

Branch name - select an existing branch by name.

Branch pattern - specify a branch using branch pattern syntax for matching branch names.

Branching model - select the branch type to restrict access to.

Select the type of actions you want to prevent.

Branch deletion - prevents branch and tag deletion.

Rewriting history - prevents history rewrites on the specified branch(es) - for example by a force push or rebase.

Changes without a pull request - prevents pushing changes directly to the specified branch(es); changes are allowed only with a pull request.

All modifications - prevents pushes to the specified branch(es) and restricts creating new branches matching the specified branch(es) or pattern.

Optional: Add exemptions for any of the selected restrictions. Adding a user or group as an exemption means that it will not apply to them. This is not required; not adding any exemptions means the restriction will apply to everyone.

Click Create to finish.

Source
Using GitHub
A repository can have multiple protected branch rules that affect the same branches.
Protected branches are available only in public repositories with GitHub Free.
Protected branch in GitHub can be configured to require:

pushes to be made via pull requests and reviewed before being merged,

other branches to pass status check before being merged,

commits to be signed,

history to be linear,

that the above rules are enforced even for administrators,

that pushes come from specific people, teams or applications,

Force pushes and deletions can be allowed independently.
To protect a branch:

On GitHub, navigate to the main page of the repository.

Under your repository name, click Settings.

In the left menu, click Branches.

Next to "Branch protection rules", click Add rule.

Under "Branch name pattern", type the branch name or pattern you want to protect (Impacted branches are listed and counted).

Configure specific branch rule settings if needed.

Click Create or Save changes.

Source
Using GitLab
In GitLab, protecting a branch does the following:

it prevents its creation, if not already created, from everybody except users with Master permission
it prevents pushes from everybody except users with Master permission
it prevents anyone from force pushing to the branch
it prevents anyone from deleting the branch

To protect the branch:

Navigate to the main page of the project.

In the upper right corner, click the settings wheel and select Protected branches.

From the Branch dropdown menu, select the branch you want to protect and click Protect.

Once done, the protected branch will appear in the "Already protected" list.

You can then allow some access to users with developer rights by checking "Developers can merge" or "Developers can push"
Source


[System] You are a helpful assistant.

[User]
How to uninstall gitlab from local ubuntu 14.04 server

How do I uninstall gitlab?
I deleted the /home/gitlab directory but it still opens up when I browse to my hostname.

[Assistant]
This worked on ubuntu 16.04
sudo apt-get remove gitlab-ce

sudo rm -rf /var/opt/gitlab

--kill all process live
sudo pkill -f gitlab

-- Remove paths
sudo rm -rf /opt/gitlab

sudo rm -rf /etc/gitlab

rm -rf /var/opt/gitlab


[System] You are a helpful assistant.

[User] git-blame - Show what revision and author last modified each line of a file  --reverse <rev>..<rev>

[Assistant]
Walk history forward instead of backward. Instead of showing
the revision in which a line appeared, this shows the last
revision in which a line has existed. This requires a range of
revision like START..END where the path to blame exists in
START. git blame --reverse START is taken as git blame
--reverse START..HEAD for convenience.


[System] You are a helpful assistant.

[User] git-check-ignore - Debug gitignore / exclude files  -q, --quiet

[Assistant]
Don’t output anything, just set exit status.  This is only
valid with a single pathname.


[System] You are a helpful assistant.

[User]
Can I comment out a line in a .git/config file?
I have a http.proxy line on my repository configuration file that I would like to 'turn on and off' easily without having to remember and type again the whole configuration every time I'm behind or free from this proxied connection.
Another possibility would be to use this repository configuration file when I'm behind the proxy and when not, use a global/local configuration file without any proxy setup.

[Assistant]
Yes, you can comment lines out of Git config files using # or ;.
From the documentation:

Syntax
The syntax is fairly flexible and permissive; whitespaces are mostly ignored. The # and ; characters begin comments to the end of line, blank lines are ignored.


[System] You are a helpful assistant.

[User] git-clone - Clone a repository into a new directory

[Assistant]
SYNOPSIS git clone [ --template= <template-directory> ]
	  [ -l ] [ -s ] [ --no-hardlinks ] [ -q ] [ -n ] [ --bare ] [ --mirror ]
	  [ -o <name> ] [ -b <name> ] [ -u <upload-pack> ] [ --reference <repository> ]
	  [ --dissociate ] [ --separate-git-dir <git-dir> ]
	  [ --depth <depth> ] single-branch ] [ --no-tags ]
	  [ --recurse-submodules [ = <pathspec> ]] shallow-submodules ] remote-submodules ] [ --jobs <n> ] [ --sparse ] reject-shallow ]
	  [ --filter= <filter-spec> ] [ --also-filter-submodules ]] [ -- ] <repository> [ <directory> ]


[System] You are a helpful assistant.

[User] git-log - Show commit logs  %cD

[Assistant] committer date, RFC2822 style


[System] You are a helpful assistant.

[User]
Renaming a branch while on pull request

On Github, you can make pull requests to add functionality to a project. One's contributions have to be on a branch that, if the request is accepted, will be merged into the master branch (or an analogous one) of the project.
Now, I submitted a pull request on Github and my contributions are on a branch called patch-1. I can modify the name of the branch locally by
git branch -m patch-1 newname

and in principle I can also rename it on my forked repo on Github by following the instruction found in this answer. This is done in practice by removing the old branch, patch-1 in my case, and repush it with a different name newname.
Is it allowed to rename the branch patch-1 on my forked repository on Github when it constitutes a pull request?
Or it causes problems on the pull request management?
Is there any way to rename a branch on a forked repository on Github when that branch is a pull request?

[Assistant]
"Renaming" a remote branch in git, as indicated by the link you provided, is really just deleting a branch, followed by pushing a new one with the same commit hash but a new name.  If you have a pull request open for branch patch-1, when you delete that branch, the pull request will be closed.
So, no you can't rename the branch with a pull request open without deleting the branch and removing the pull request.  However, there's nothing stopping you from doing that, pushing a new branch with a new name, and creating a new pull request.


[System] You are a helpful assistant.

[User]
what should be in .gitignore file for a netbeans java project?
What should be the content of the .gitignore file for a java project in netbeans?

[Assistant]
# NetBeans specific #
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml

# Class Files #
*.class

# Package Files #
*.jar
*.war
*.ear


[System] You are a helpful assistant.

[User]
How to unsubscribe from all repos within an organisation

After you join an Organization on Github you automatically subscribed to all of its repos and you start getting all those updates you don't really want. To unsubscribe you need to go per repo and do it manually. Is it possible to unsubscribe from all repos within a particular Organisation at once?

[Assistant]
You can unsubscribe from all repos or one by one under https://github.com/watching
Maybe not exactly the best way but I find it useful. Hope it helps!


[System] You are a helpful assistant.

[User]
.gitignore: How do I ignore nested directories?
I have the following directory structure:
test/a
test/b/c
test/a/b/Ouput
test/c/d/e/Output
test/f/Output

I want to ignore all the "Output" directories under "test".  I tried test/**/Output, but it didn't work.  What am I doing wrong?

[Assistant]
You said you want the Output/ pattern to match only under the test/ directory, so in the test/ directory, create a .gitignore file with the contents:
Output/

If you put this pattern in your top-level .gitignore file, then it will match in all directories under the top directory.


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  Munging the diff output

[Assistant]
$ git diff --find-copies-harder -B -C (1) $ git diff -R (2) Spend extra cycles to find renames, copies and complete
rewrites (very expensive). Output diff in reverse.


[System] You are a helpful assistant.

[User] git-branch - List, create, or delete branches  --format <format>

[Assistant]
A string that interpolates %(fieldname) from a branch ref being shown
and the object it points at.  The format is the same as
that of git-for-each-ref .