Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - Make local HEAD the new master

Tags:

git

I decided to go back a few commits because the path I followed was wrong. So I checked out Added cordova to .gitignore commit, and made some modifications. Like illustrated below :

enter image description here

Now when I push the new modifications, an error message shows up :
error: src refspec (detached from aad6423) does not match any.

How can I tell git to discard the previous commits (in purple) and continue with my local HEAD as master ?

like image 886
Mehdiway Avatar asked Nov 12 '14 16:11

Mehdiway


People also ask

How do I point my head to the origin master?

the HEAD is not stepping onto any branch, then above commands do: checkout the target commit (you're already stepping there, but just in case) move master pointer to that commit (no problem, since it is a forward move) checkout master branch in order to be stepping onto it (for future commits)


2 Answers

Make HEAD your new local master:

$ git checkout -B master

Force-push your changes:

$ git push -f
like image 176
Tavian Barnes Avatar answered Oct 02 '22 05:10

Tavian Barnes


Even though you don't want that old branch anymore, git really doesn't like rewriting history or discarding changes. Just revert and merge.

git branch new_master              # name current detached HEAD
git checkout master                # switch back to master
git revert --no-edit HEAD~4..HEAD  # create commits reverting back to where the history split
git merge new_master               # merge
git branch -d new_master           # don't need it anymore
like image 42
Max Avatar answered Oct 02 '22 05:10

Max