making a git push from a detached head

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 certainly not on the master branch. I am working on a file with another individual.

Example branches

   develop
   master
   *(HEAD detached at origin/49792_testMocha)

How do I push into head without affecting develop or master?


Create a new branch using git checkout -b BRANCH_NAME

Then push the new branch to remote: git push origin BRANCH_NAME


If you are on a detached head and you want to push to your remote branch

git push origin HEAD:name-of-your-branch

otherwise you can create a new branch and push to it ( it will be created automatically )

git branch new-branch-name
git push -u origin new-branch-name


git checkout

git checkout <commit_id>
git checkout -b <new branch> <commit_id>
git checkout HEAD~X // x is the number of commits t go back

This will checkout new branch pointing to the desired commit.
This command will checkout to a given commit.
At this point you can create a branch and start to work from this point on.

# Checkout a given commit. 
# Doing so will result in a `detached HEAD` which mean that the `HEAD`
# is not pointing to the latest so you will need to checkout branch
#in order to be able to update the code.
git checkout <commit-id>

# create a new branch forked to the given commit
git checkout -b <branch name>
链接地址: http://www.djcxy.com/p/8632.html

上一篇: 如何将不同的本地Git分支推送到Heroku / master

下一篇: 从一个分离的头部推动git推动