Why do I need to explicitly push a new branch?

前端 未结 8 1728
遥遥无期
遥遥无期 2020-11-22 00:48

I am new in git and I am practicing. I created a local branch but I saw that when I did git push my branch was not uploaded to the repository. I ha

8条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 01:04

    I just experienced a further permutation of this issue.

    I had a branch named feat/XYZ-1234-some-description because I was working on Jira issue 1234. During the work I created a new Jira issue to track a smaller piece of work, and when I came to push I decided to push to a branch name with this new issue number in:

    git push -u origin feat/XYZ-5678-a-different-description # failed
    

    This gave me the error being discussed in this SO thread. But since I was trying to push to a different branch name from my current branch, my problem was different to the one described here. I ended up renaming my local branch before I could push it:

    git branch -m feat/XYZ-1234-some-description feat/XYZ-5678-a-different-description
    git push -u origin feat/XYZ-5678-a-different-description # now works
    

    After a bit more reading around I realised that I could have set a src on the git push, either to the current branch name, or just HEAD if appropriate:

    git push -u origin feat/XYZ-1234-some-description:feat/XYZ-5678-a-different-description # also works
    

提交回复
热议问题