Making a Git push from a detached head

前端 未结 6 951
时光说笑
时光说笑 2020-11-29 20:05

I am on a detached head and made some changes. I want to push up these changed to this detached head with Git. I do not want my changes to go onto the develop branch and cer

6条回答
  •  悲&欢浪女
    2020-11-29 20:46

    While all the answers here sort of answer the original question (how to push from a detached head without affecting other branches) all suggest creating a new branch.

    Here's how to push to a new remote branch without creating a new local branch:

    git checkout --detach # (or anything else that leaves you with a detached HEAD - guillotine anyone?)
    [change stuff & commit]
    git push origin HEAD:refs/heads/my-new-branch
    

    Replace origin with the appropriate remote name (that you have write access to), and my-new-branch with whatever you want the new branch to be called.

    Your commit(s) on HEAD will be pushed to a new branch named my-new-branch.

提交回复
热议问题