How can you git pull only the current branch?

Is there a tuning method to set this without specifying which branch?

+45
git config pull
May 18 '11 at 23:03
source share
5 answers

Git already pulls only the current branch. If you have a branch configured as a tracking branch, you do not need to specify a remote branch. git branch --set-upstream localbranch reponame/remotebranch establish a tracking relationship. Then you send git pull [--rebase] , and only this branch will be updated.

Of course, all remote tracking branches and all refs for the remote will be updated, but only your local tracking branch will be changed.

+53
May 18 '11 at 23:07
source share

I just did this:

 git pull origin "$(git branch | grep -E '^\* ' | sed 's/^\* //g')" 

or

 git pull origin $(git rev-parse --abbrev-ref HEAD) 

This extracts the current branch from git branch and pulls this branch from a remote source.

Note that, as Set Robertson said, when no arguments are given, only the current branch changes, but all deleted branches are selected. I do not want to receive all deleted branches, so I did it like this.

+24
Apr 27 '14 at 21:44
source share

Try this for the new git version:

 $ git config --global push.default current 
+15
Feb 09 '15 at 20:11
source share

The --set-upstream flag is deprecated and will be removed. Hence use --track or --set-upstream-to

Example: If you want to set tracking information for this branch, you can do this with:

 git branch --set-upstream-to=<remote>/<branch> develop 
+3
Jul 10 '15 at 9:26
source share

Yes, there is a config that can be changed in .gitconfig , for example:

 [push] default = current 

which will force the current branch to update the branch with the same name on the receiving side.

Note:

 git config --global --get push.default 

See: git-config .

+2
Oct 24 '15 at 17:11
source share



All Articles