Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a Git push from a detached head

Tags:

git

git-push

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?

like image 693
Winnemucca Avatar asked Mar 02 '16 00:03

Winnemucca


People also ask

How do you push changes from a detached head?

If you find yourself in the detached HEAD state, remember that you can always preserve your changes by creating and checking out to a new branch, then committing and merging the changes in the desired branch. If you do not want to save the changes, you can simply check out to any branch, and Git removes those commits.

How do I fix the detached head at origin master?

All you have to do is 'git checkout [branch-name]' where [branch-name] is the name of the original branch from which you got into a detached head state. The (detached from asdfasdf) will disappear. Show activity on this post. And head is re attached!


1 Answers

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 
like image 122
Mohamed Salem Lamiri Avatar answered Oct 28 '22 23:10

Mohamed Salem Lamiri