Skip to content

Instantly share code, notes, and snippets.

@jhoff
Created February 16, 2013 05:42
Show Gist options
  • Save jhoff/4965700 to your computer and use it in GitHub Desktop.
Save jhoff/4965700 to your computer and use it in GitHub Desktop.
Fixing a diverged master branch
# This is the easiest way to "reset" your master branch if you've jacked it up
# 1) Make sure you have a clean working directory
git status
# 2) Create a new temporary branch
git checkout -b temp_branch
# 3) Push the new temp_branch to github
git push origin temp_branch
# 4) Goto your repo on github, goto settings and change the "default branch" to temp_branch
# 5) Delete your local and remote master branches
git branch -D master
git push origin :master
# 6) Add a remote for the upstream repo ( the one you forked off from )
git remote add upstream [git read-only url]
# 7) Fetch the upstream data
git fetch upstream
# 8) Checkout upstream master
git checkout upstream/master
# 9) Make a new local master branch
git checkout -b master
# 10) Push your fancy new master branch to github
git push origin master
# 11) Head on back to the github repo settings page and set your "default branch" back to "master"
# 12) Delete your local and remote temporary branches
git branch -D temp_branch
git push origin :temp_branch
DONE!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment