Skip to content

Instantly share code, notes, and snippets.

@bhuvidya
Last active February 1, 2018 06:32
Show Gist options
  • Save bhuvidya/9f25836a038e5502ab566381e910e484 to your computer and use it in GitHub Desktop.
Save bhuvidya/9f25836a038e5502ab566381e910e484 to your computer and use it in GitHub Desktop.
Miscellaneous Git Commands, Tricks etc

Reset head of local and remote master

I had a repo once where master had gone off on a tangent from develop, stuff another developer did, and I wanted to bring it back to the commit where it first forked off from develop. Even though the remote origin had been synced with local master, I knew that no other developer had worked on that branch, and I could safely revert. So just say the commit I wanted to revert to was 56b33e4:

# make sure we are on master
$ git checkout master

# reset local branch HEAD back to desired commit
$ git reset --hard 56b33e4

# force remote "master" to point to same commit
$ git push origin +56b33e4:master

# remove unwanted origin/HEAD branch (which was pointing to origin/master)
$ git remote set-head origin -d

Some handy links:

https://stackoverflow.com/questions/9529078/how-do-i-use-git-reset-hard-head-to-revert-to-a-previous-commit https://stackoverflow.com/questions/4114095/how-to-revert-git-repository-to-a-previous-commit https://stackoverflow.com/questions/354312/why-is-origin-head-shown-when-running-git-branch-r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment