difference between origin/branch_name and branch_name?

前端 未结 4 1767
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 02:26

for pushing to bitbucket.

If I do: git push origin origin/branch_name my commits are not pushed.

Total 0 (delta 0), reused 0 (delta 0)
<         


        
4条回答
  •  [愿得一人]
    2020-11-29 02:57

    You have to keep in mind that there are different types of branches:

    • (Purely) local branches, i.e. branches you commit to,
    • Branches that live in a remote repository, for lack of a better term. You may know the remote repository in question under a remote name, such as origin. From that repository's point of view, though, such a branch is local. Welcome to Distributed Version Control! :)
    • Remote-tracking branches. Also simply called remote branches, as in the Pro Git book, but I find this phrase confusing; remote-tracking branch is more accurate. They're special local branches whose sole purpose is to reflect the state of branches that live in a remote repository at the time of your last communication with the server. In particular, you can't commit to branches of this type.

    Here, branch_name is a local branch, whereas origin/branch_name is a remote-tracking branch; it reflects the state of the corresponding branch that lives in origin.

    Right after running

    git fetch
    

    the remote-tracking branch origin/master and the corresponding branch that live in origin should be perfectly in sync (modulo concurrent pushes to the remote server, of course). It shouldn't be a surprise, then, that

    git push origin origin/branch_name
    

    doesn't push anything: you're essentially attempting to push stuff that is already present in the ancestry of the corresponding branch that live in origin .

    However, if your local branch, branch_name, is ahead by one or more commits,

    enter image description here

    then running

    git push origin branch_name
    

    will push the commits contained in branch_name but not in the branch that live in origin:

    enter image description here

提交回复
热议问题