simple – in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch's name is different from the local one. matching – push all branches having the same name on both ends. This makes the repository you are pushing to remember the set of branches that will be pushed out.
By default, Git chooses origin for the remote and your current branch as the branch to push. If your current branch is main , the command git push will supply the two default parameters—effectively running git push origin main .
All branches having the same name in both ends are considered to be matching.
With that policy, only a simple git push is enough to push all (matching) branches. Without that policy, a git push --all is necessary to force all branches to be pushed.
The difference is that with simple
, git push
(without passing a refspec) will fail if the current branch isn't tracking a remote upstream branch (even if a branch with the same name exists on the remote):
$ git checkout -b foo
Switched to a new branch 'foo'
$ git config push.default simple
$ git push
fatal: The current branch foo has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin foo
On the other hand, current
doesn't care about whether or not the current branch tracks an upstream, it just wants to push to any branch that has the same name:
$ git config push.default current
$ git push
Total 0 (delta 0), reused 0 (delta 0)
To /Documents/GitHub/bare
* [new branch] foo-> foo
From the Git configuration documentation:
upstream
- push the current branch to its upstream branch...
simple
- like upstream, but refuses to push if the upstream branch’s name is different from the local one...
current
- push the current branch to a branch of the same name.
The difference is that simple
pushes to its tracking branch if it has the same name, while current
will push to a branch of the same name regardless of any tracking branch:
$ git branch -vvv
master 58d9fdc [origin/master: ahead 1] t1 bobo
* new 37132d3 [origin/save: ahead 1] t1 bibi # <- tracking branch 'save'
$ git -c push.default=current push # <- set `push.default=current`
Counting objects: 3, done.
Writing objects: 100% (3/3), 234 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /home/jthill/sandbox/20/t1
* [new branch] new -> new # <- and push creates `new`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With