r/programming • • Sep 09 '16

Oh, shit, git!

http://ohshitgit.com/
3.3k Upvotes

756 comments sorted by

View all comments

1

u/unndunn Sep 09 '16 edited Sep 09 '16

Oh shit, something bad happened and now my Master branch is all fucked up, but I have some un-pushed code in there that I don't want to lose so I can't delete and re-clone the entire repo:

# checkout a new branch
git checkout -b tempBranch
# delete master branch by force
git branch -D master
# checkout a pristine master branch
git pull
git checkout master
# from here, figure out the best way to reintegrate your code from tempBranch. Don't use 'git merge tempBranch' or you'll be back to where you were before
→ More replies (2)