Why is git pushing to two branches in this git push?

前端 未结 2 2107
陌清茗
陌清茗 2021-02-07 06:25

What would possibly cause a \'git push\' to try and commit to two branches? I have my own branch I\'m working on, which is on the shared repo... and a master branch. Right now I

相关标签:
2条回答
  • 2021-02-07 06:50

    When using git push without any arguments, it will push all local branches that have a corresponding remote branch with the same name. Since your local repository has branches masterand mybranch, and also the remote repository has branches masterand mybranch, then Git will push both of them.

    If you want to push only one branch, you can say to Git explicitly that which branch you want to push: git push origin mybranch

    If you want to push master, you can fix that error by first pulling from master. Git complains about the merge being non-fast forward, because somebody else has pushed a commit to master since the last time that you pulled from master.

    0 讨论(0)
  • 2021-02-07 07:12

    If you want to push only current branch, you can use "git push origin HEAD", or perhaps even "git push HEAD" (with modern git).

    The default behavior if no refspec for push (you have defined refspec for fetch in your config, but not for push) is to push matching refs. From git-push(1):

    git push [...] [<repository> <refspec>...]

    <refspec>...

    The special refspec : (or +: to allow non-fast forward updates) directs git to push "matching" branches: for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side. This is the default operation mode if no explicit refspec is found (that is neither on the command line nor ...

    0 讨论(0)
提交回复
热议问题