Is there a config way to set this up without having to specify which branch?
6 Answers
Git already only pulls the current branch. If you have branch set up as a tracking branch, you do not need to specify the remote branch. git branch --set-upstream-to=reponame/remotebranch localbranch
will set up the tracking relationship. You then issue git pull [--rebase]
and only that 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 modified.
Useful Bash alias to cut down on typing of this common operation:
# Add an alias to pulling latest git changes into your same branch
alias pullhead='git pull origin $(git rev-parse --abbrev-ref HEAD)'
Powershell function that does the same:
Function pullhead {
$cur_head="$(git rev-parse --abbrev-ref HEAD)"
& git pull origin ${cur_head}
}

- 30,608
- 7
- 64
- 57
-
that right, and maybe a bit strange because "git push" (as default) tries to push all the branches (with the same remote name). – Alessandro De Simone Sep 03 '13 at 13:58
-
2@AlessandroDs Well, I set push.default to upstream for just that reason. The new default for push.default is "simple" which again only updates the current branch, so is far more parallel to what pull does. – Seth Robertson Sep 04 '13 at 03:50
-
@SethRobertson: Thanks for the answer, are you able to elaborate on that last part at all? By modified, do you mean changes don't get pulled from the remote repo? We're finding that with several branches at ~100MB each, when we do a pull we get several ~100MB downloads occurring (all branches, basically). – danjah Oct 09 '14 at 21:22
-
2@Danjah: All changes get pulled from the remote repo (into remote tracking branches, eg origin/master origin/foo, etc). If you are checked out into a local branch with an upstream defined, only that local branch will be updated. If you are checked out into a local branch without an upstream, then you must specify more information or set the upstream. Do not attempt to modify a non-local checkout, create a local branch and proceed. If you want to reduce what you transfer, you can update your remote's refspec in your local git config. – Seth Robertson Oct 10 '14 at 12:59
-
3Is there a built-in way to not update all refs only fetch the current branch? – Aditya M P Feb 20 '15 at 07:54
-
1@aditya menon: Not easily. You would need to update the refspec (eg git config remote.origin.fetch) to only fetch the specific refs (branches, tags, etc) that you want. See https://stackoverflow.com/questions/15507264/can-i-specify-in-git-config-to-fetch-multiple-refspecs for more specific examples. – Seth Robertson Feb 20 '15 at 14:10
-
1why then on this page: https://git-scm.com/book/en/v2/Git-Internals-The-Refspec it specifies that in the "default case, it pulls all branches", and if you need to pull only master, you need to specify it in the refspecs.. ? – Matt Jan 07 '19 at 16:54
-
@Matt: Different uses of the word "pull". I said that "Of course, all remote tracking branches and all refs for the remote will be updated". If you want to only update the master remote tracking branch, you would have to modify the refspec. However, I used "pull" in the `git pull` sense, of updating something you woud typically check out--and using that definition, only one branch is pulled. – Seth Robertson Jan 08 '19 at 03:28
-
1`fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead.` – neaumusic Mar 03 '23 at 18:43
I just did it this way:
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 that branch from remote origin.
Note, that like Seth Robertson said, when no arguments are given only the current branch is modified but all remote branches are fetched. I don't want to fetch all remote branches, so I did it this way.

- 10,029
- 11
- 83
- 152

- 1,582
- 12
- 14
-
3`git branch` shouldn't really be parsed for branch information. That information is available with `git rev-parse` making the command: `git pull origin $(git rev-parse --abbrev-ref HEAD)` – Paul DelRe Aug 09 '16 at 13:24
-
@ayke I added Paul DelRe answer into yours as it also worked, I hope you both don't mind – Timo Huovinen Nov 11 '16 at 15:00
-
1Just curious: What is the difference between a simple "git pull" (having checked out the branch I want to pull) and your suggestion? Your command substitution results in `git pull origin
` which is the default anyway, isn't it? Are you implying that the other remote branches (e.g. origin/other-branch etc.) aren't updated, so that traffic is reduced? – Peter - Reinstate Monica Sep 19 '17 at 13:22 -
I answered this ages ago, I don't really know anymore. You should probably go with the accepted answer... – ayke Sep 29 '17 at 16:55
-
@PeterA.Schneider If you just type `git pull` you might end up with a message like `There is no tracking information for the current branch. Please specify which branch you want to merge with.`. Then you always end up typing `git pull origin my-feature-branch`. I'd really like to know how this situation arrives that there is no tracking information. – Alfe Jul 16 '18 at 12:46
-
`git pull origin $(git branch --show-current)` which is more easy to remember. – RN Kushwaha Aug 18 '20 at 07:44
UPDATE
The old answer i've add does not work any more :/. But after receive some upvotes about the PUSH version I've placed, to me means this answer is actually helping someone that ending coming here from search engines, so I'll keep this answer.
Try this for the new version of git:
$ git config --global push.default current

- 1,339
- 2
- 17
- 32
-
10I do not believe pull.default exists. See [git-scm](http://git-scm.com/docs/git-config.html) or [kernel.org](https://www.kernel.org/pub/software/scm/git/docs/git-config.html) . – Mort Jun 16 '15 at 13:15
-
2Yes. git 2.3.4 on linux fetches all branches even with with the above `pull.default=current`. I see that my `git clone` by default also added `remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*` but that's pretty standard. – Mort Jun 18 '15 at 01:35
-
7There is no `pull.default` config variable. Putting that in your git config won't do anything. – David Sanders Nov 19 '15 at 22:14
-
9Question is about git pull, and the answer contains git push with many upvotes. This is misleading @BrunoCasali Why did you edit your answer and removed it if it worked for you? If you realize the answer is wrong please delete it instead of keeping it with irrelevant information to keep the upvotes. – T J Jul 19 '17 at 11:49
The --set-upstream
flag is deprecated and will be removed.
Hence, use --track
or --set-upstream-to
Example: If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=<remote>/<branch> develop

- 8,099
- 9
- 49
- 58
-
It might be deprecated (source?) but `--set-upstream-to=` keeps being mentioning by git when it does not know about your tracking information. With no mention of deprecation. – Adrien Apr 03 '17 at 15:13
-
@AdrienGiboire Here is some info about the deprecation: https://jira.atlassian.com/browse/SRCTREEWIN-588 – biniam Apr 05 '17 at 02:40
Here's a git alias that doesn't assume the remote is origin
and handles if the branch isn't tracking a remote.
pullh = "!f() { set -e; set -o pipefail; arr=($(git rev-parse --abbrev-ref @{u} | sed 's/\\//\\n/')); git pull ${arr[0]} ${arr[1]}; }; f"
(Disclaimer: I'm very much a bash novice and the above could probably be simplified a lot.)

- 14,252
- 13
- 80
- 114
Yes, there is a config which can be changed in .gitconfig
, for example:
[push]
default = current
which would push the current branch to update a branch with the same name on the receiving end.
Check by:
git config --global --get push.default
See: git-config.

- 155,785
- 88
- 678
- 743
-
2The question was regarding `git pull` not `git push` so I downvoted your answer to prevent people thinking this is the solution – Manse Feb 04 '21 at 08:52