I have read the git man about push command, but I still don't understand the EXACT difference between current and upstream to be set in the push.default
I want that our team will just do push, and only changes on the branch that they are currently working on, will be pushed. As I understand, this branch is the one that marked with * (star) when I do git branch.
Thanks for helping out.
When you set your upstream (or tracking) branches, you can simply execute pulls and pushes without having to specify the target branch. Git automatically knows that it has to fetch the new commits to the remote tracking branch. Similarly, Git already knows that it has to push new commits to the upstream branch.
Option -u or --set-upstream allows to add upstream (tracking) reference for every branch that is up to date or successfully pushed. For example, my local repository is checkout in issue-1 : if I want to push it to origin and add upstream reference as origin/issue-1 , I can do: $ git push -u origin issue-1.
pushing " upstream " means that your current branch B has remote/B has its upstream branch. Ie: branch. B. merge is set, when your are pushing the " upstream " branch. Ie: when pulling to B , git knows what branch to pull (as well as which remote repo: branch.B.remote )
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 .
The question is what are you pushing, and to where:
current
:
upstream
:
As explained here, Git2.0 will additionally introduce a new default for push.default
: simple
simple
is like upstream
, but the upstream has to have the same name as well or the push will fail.
Pushing only one branch (with the mode "simple
", "current
" or "upstream
") avoids the scenario where all matching branches are pushed (mode "matching
", which was the default for a long time), even though some of your branches might not be ready to be pushed.
(master)> git push ... To [email protected]:jkubicek/my_proj.git 21b430d..dd378ca master -> master ! [rejected] release -> release (non-fast-forward) error: failed to push some refs to '[email protected]:jkubicek/my_proj.git' hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. hint: If you did not intend to push that branch, you may want to hint: specify branches to push or set the 'push.default' configuration hint: variable to 'current' or 'upstream' to push only the current branch.
The difference between the two (current
and upstream
) is in the pull (what to pull from the remote to your branch?):
pushing "current
" doesn't mean that your current branch B
has remote/B
has its upstream branch.
Ie: branch.B.merge
isn't set, when your are pushing the "current
" branch.
Ie: when pulling to B
, git won't know what branch to pull.
pushing "upstream
" means that your current branch B
has remote/B
has its upstream branch.
Ie: branch.B.merge
is set, when your are pushing the "upstream
" branch.
Ie: when pulling to B
, git knows what branch to pull (as well as which remote repo: branch.B.remote
)
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