Take the 2-minute tour ×

I use the following command to push to my remote branch:

git push origin sandbox

If I say

git push origin

Does that push changes in my other branches too, or does it only update my current branch? (I have three branches: master, production and sandbox).

(The git push documentation is not very clear about this, so I'd like to clarify this for good)

What branches/remotes do the following git push commands exactly update?

git push 
git push origin

("origin" above is a remote)

(I understand that "git push [remote] [branch]" will push only that branch to the remote)

share|improve this question
Regarding the configuration of diff tools in general, and the new script git difftool, I have added a new answer in this other SO question: stackoverflow.com/questions/255202/… –  VonC Jun 4 '09 at 8:29
I did a blog post about the surprising behaviour of git push, which might be of interest –  Mark Longair Mar 4 '11 at 7:28
@Mark: in other work, pushing only the current branch to its tracked upstream. Nice. –  VonC Mar 4 '11 at 7:42
add comment

11 Answers

up vote 614 down vote accepted

You can control the default behavior by setting push.default in your git config. From the git-config(1) documentation:


Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line. Possible values are:

  • nothing: do not push anything

  • matching: push all matching branches

    All branches having the same name in both ends are considered to be matching.

    This is the default in Git 1.x.

  • upstream: push the current branch to its upstream branch (tracking is a deprecated synonym for upstream)

  • current: push the current branch to a branch of the same name

  • simple: (new in Git 1.7.11) like upstream, but refuses to push if the upstream branch's name is different from the local one

    This is the safest option and is well-suited for beginners.

    This will become the default in Git 2.0.

The simple, current and upstream modes are for those who want to push out a single branch after finishing work, even when the other branches are not yet ready to be pushed out

Command line example:

git config --global push.default current
share|improve this answer
It's probably worth noting that this is new in v1.6.3: kernel.org/pub/software/scm/git/docs/RelNotes-1.6.3.txt –  Charles Bailey Jun 4 '09 at 7:34
This "push.default" is the greatest thing ever for working with multiple repos. Set it to "tracking" and you are all good. Combined with branch --set-upstream these making push and pull way more convenient. –  orange80 Sep 30 '10 at 4:22
According to the git doc 'git push origin HEAD' should also work. –  Kutzi Mar 26 '11 at 10:31
"tracking" is the deprecated synonym for "upstream": kernel.org/pub/software/scm/git/docs/git-config.html –  MartinVonMartinsgrün Jun 9 '11 at 6:37
It's worth noting that as of Git 1.7.11, there's a new simple mode. This mode is intended to become the default in future. simple works like upstream, but like current requires that the branch names are the same on both ends. –  Kai Oct 14 '12 at 20:59
show 8 more comments

git push origin will push all changes on the local branches that have matching remote branches at origin As for git push

Works like git push <remote>, where <remote> is the current branch's remote (or origin, if no remote is configured for the current branch).

From the Examples section of the git-push man page

share|improve this answer
Yep, that makes it clear. I'm probably running an older version of git ( Mac OS X) which does not have these examples in the man page. –  Nocturne Jun 4 '09 at 3:53
Probably I'm running I did find it on the site I linked however. –  baudtack Jun 4 '09 at 3:56
So, in my case, where all the local branches have the same remote "origin", "git push" would be exactly the same as "git push origin" which would push only the local branches that have a corresponding branch in the remote. –  Nocturne Jun 4 '09 at 4:02
@Debajit Right on! Great question by the way. I had always assumed that git push would only push the current branch. Apparently not! Very good to know. –  baudtack Jun 4 '09 at 4:28
This question is old but for anybody new, @docgnome is right. Just running 'git push origin' will push all of the branches instead of only the current branch. Use 'git push -f -v -n origin development' to force push a branch named development. Use the -n flag to simulate the git push result so you can see in advance which branch(es) will be affected. If it looks good then run 'git push -f -v origin development'. This might be useful stackoverflow.com/questions/3741136/git-push-f-vs –  Dylan Valade Sep 19 '11 at 13:42
add comment

You can set up default behavior for your git with push.default

git config push.default current

or if you have many repositories and want the same for all then

git config --global push.default current

The current in this setup means that by default you will only push the current branch when you do git push

Other options are:

  • nothing : Do not push anything
  • matching : Push all matching branches (default)
  • tracking : Push the current branch to whatever it is tracking
  • current : Push the current branch


As of Git 1.7.11 do the following:

git config --global push.default simple

This is a new setting introduced that works in the same way as current, and will be made default to git from v 2.0 according to rumors

share|improve this answer
Your answer is an exact duplicate of the most upvoted one... –  CharlesB Oct 6 '11 at 11:12
Yes I read the answer you are referring to, but that answer only tells what to do and not how to do it. So I added my answer so all the info needed to set it up is on the same page. –  Christoffer Oct 11 '11 at 9:46
OK; it's better to suggest an edit to the said post, because nobody will see your answer, as it's not likely to get as many votes –  CharlesB Oct 11 '11 at 9:56
I think this answer is definitely most useful for me :) –  Kenny Cason Nov 21 '11 at 8:01
how would one go about pulling to current branch? git pull origin? –  Francois Oct 22 '12 at 12:36
add comment

I just committed my code to a branch and pushed it to github, like this:

git branch SimonLowMemoryExperiments
git checkout SimonLowMemoryExperiments
git add .
git commit -a -m "Lots of experimentation with identifying the memory problems"
git push origin SimonLowMemoryExperiments
share|improve this answer
Perfect answer..solves my need exactly. Thanks for this :) –  AdityaSaxena Aug 21 '13 at 6:21
add comment

I just put this in my .gitconfig aliases section and love how it works:

pub = "!f() { git push -u ${1:-origin} `git symbolic-ref HEAD`; }; f"

Will push the current branch to origin with git pub or another repo with git pub repo-name. Tasty.

share|improve this answer
That is nice, but it unfortunately assumes that the branch has the same name on the other repository. Try git push -u --repo="origin" $1; instead. It works quite well, except if you push to another repository, the branch name will be the name used by the other repository, not the one you are pushing from –  Casebash Jan 9 '12 at 7:11
Hey thanks! Makes me wanna do a more complete version that checks the tracking status before pushing. But I'll stick with mine for now since I rarely have different branch names between repos. –  Mat Schaffer Jan 9 '12 at 16:22
add comment

(March 2012)
Beware: that default "matching" policy might change soon
(sometimes after git1.7.10+)

See "Please discuss: what "git push" should do when you do not say what to push?"

In the current setting (i.e. push.default=matching), git push without argument will push all branches that exist locally and remotely with the same name.
This is usually appropriate when a developer pushes to his own public repository, but may be confusing if not dangerous when using a shared repository.

The proposal is to change the default to 'upstream', i.e. push only the current branch, and push it to the branch git pull would pull from.
Another candidate is 'current'; this pushes only the current branch to the remote branch of the same name.

What has been discussed so far can be seen in this thread:


Previous relevant discussions include:

To join the discussion, send your messages to: git@vger.kernel.org

share|improve this answer
add comment

Here is a very handy and helpful information about Git Push: Git Push: Just the Tip

The most common use of git push is to push your local changes to your public upstream repository. Assuming that the upstream is a remote named "origin" (the default remote name if your repository is a clone) and the branch to be updated to/from is named "master" (the default branch name), this is done with: git push origin master

git push origin will push changes from all local branches to matching branches the origin remote.

git push origin master will push changes from the local master branch to the remote master branch.

git push origin master:staging will push changes from the local master branch to the remote staging branch if it exists.

Source: Git Push: Just the Tip

share|improve this answer
add comment

A git push will try and push all local branches to the remote server, this is likely what you do not want. I have a couple of conveniences setup to deal with this:

Alias "gpull" and "gpush" appropriately:

In my ~/.bash_profile

get_git_branch() {
alias gpull='git pull origin `get_git_branch`'
alias gpush='git push origin `get_git_branch`'

Thus, executing "gpush" or "gpull" will push just my "currently on" branch.

share|improve this answer
If you always want the behavior of gpush, you can also set remote.origin.push=HEAD (e.g. "git config remote.origin.push HEAD"), as mentioned in the examples section of the git-push man page. –  Trevor Robinson Jun 24 '10 at 7:57
This is not necessary if you look at the above post by "Brian L". –  orange80 Sep 30 '10 at 4:23
It is, as there is no equv. for pull pull.default –  SamGoody Jan 8 '12 at 20:36
add comment

Rather than using aliases, I prefer creating git-XXX scripts so I can source control them more easily (our devs all have a certain source controlled dir on their path for this type of thing).

This script (called git-setpush) will set the config value for remote.origin.push value to something that will only push the current branch:

#!/bin/bash -eu

CURRENT_BRANCH=$(git branch | grep '^\*' | cut -d" " -f2)

echo "setting remote.origin.push to $NEW_PUSH_REF"
git config remote.origin.push $NEW_PUSH_REF

note, as we're using Gerrit, it sets the target to refs/for/XXX to push into a review branch. It also assumes origin is your remote name.

Invoke it after checking out a branch with

git checkout your-branch
git setpush

It could obviously be adapted to also do the checkout, but I like scripts to do one thing and do it well

share|improve this answer
add comment

I have added the following functions into my .bashrc file to automate these tasks.

function gpush()
  if [[ "x$1" == "x-h" ]]; then
    cat <<EOF
Usage: gpush
git: for current branch: push changes to remote branch;
    set -x
    local bname=`git rev-parse --abbrev-ref --symbolic-full-name @{u} | sed -e "s#/# #"`
    git push ${bname}
    set +x

function gpull()
    cat <<EOF
Usage: gpull
git: for current branch: pull changes from
    set -x
    git pull ${bname}
    set +x
share|improve this answer
add comment

This happens cause the origin repository is not a bare repository. To solve this, you can clone the origin repository as bare:

git clone --bare /path/to/repository


share|improve this answer
Care to elaborate on what exactly this has to do with which branch is pushed? –  Brad Koch Apr 1 '13 at 23:55
add comment

protected by Josh Crozier May 9 at 23:01


Would you like to answer one of these unanswered questions instead?
