Configure push.default
You want to set push.default
to one of simple
, upstream
, or current
. In fact, you probably want simple
.
To set simple
mode for yourself, for all repositories where you have not set some other value, use:
git config --global push.default simple
To override this in one specific repository, use, e.g.:
git config push.default upstream
(assuming you want upstream
mode for the current repository, regardless of your --global
setting).
The "default default" depends on your version of Git.
In Git versions before 2.0, the initial default is matching
. This is the behavior you are seeing now and is clearly not what you want.
In Git versions 2.0 or later, the initial default is simple
. If this is what you want and git --version
tells you that you have 2.0 or later, you don't have to set anything.
What simple
and upstream
mean
In Git, each of your branches (your local branch names, like master
and my-branch
) can have one "upstream" setting. (Or it can have no upstream setting, but that's not very useful to us!) The main command to set or change the upstream is git branch --set-upstream-to
.
The upstream is itself essential two parts: the name of a remote, like origin
, and the name of a branch on that remote, like master
. With git branch --set-upstream-to
you just name the remote-tracking branch, origin/master
, to set both at once, and it does the obvious thing.
Once set, git push
will pick the remote from the name-of-the-remote part, and the branch to push to from the name-of-the-branch part. (The branch you are pushing from defaults to your current branch, of course, and it's this current branch's upstream that sets the other two parts.)
Let's say that your current branch is $branch
and that its upstream is $remote/$upstream_branch
. Using simple
or upstream
means that:
git push
means:
git push $remote $branch:$upstream_branch
The simple
setting adds one extra constraint: this default push will stop (refuse to run) if $upstream_branch
is not the same name as $branch
.
What current
means
Note that both of the above require that the current branch have an upstream. Using current
is sort of like using simple
, except that Git doesn't require a full upstream setting. It only needs the "remote" part. (You can write git push origin
to supply that part, or your current branch can have a remote set, with or without the other half of the upstream.) Instead of needing $upstream_branch
, git push
now just does:
git push $remote $branch:$branch
Again, the new default is simple
and that's usually the right setting.