Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

git - push current vs. push upstream (tracking)

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.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The question is what are you pushing, and to where:

  • current:

    • "what" is only your current branch (no other branches),
    • "to where" is a branch of the same name (created if it doesn't exist) in the upstream repo.
  • upstream:

    • "what" is also only the current branch,
    • "to where" is to whatever branch (not necessarily of the same name) on the upstream repo has been assigned as an upstream branch for the local branch you are pushing.

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...