How to undo git pull from unlinked project?
I just did something dumb. In my fooclient project, I just did:
git remote add official https://github.com/fooserver
git pull official master
In other words, I pulled a completely different codebase (server, not client) into my working directory. Unsurprisingly, there weren't many merge conflicts (filenames are all different after all). Also unsurprisingly, Git did not fully warn me that the repo did not have a single common ancestor.
In this particular situation, I can recover by doing the following:
cp file-i-worked-on.js ~
git reset --hard HEAD # to discard broken merge conflicts
git checkout a12345 # where a12345 is the latest head of fooclient that I had checked out
cp ~/file-i-worked-on.js .
But what will be the broader strategy?
source to share
After removing the unwanted remote ( git remote rm ...
) just git reset --hard
to where you want your current branch to be included.
git reset --hard origin/master
If you were on before master
, this resets yours master
to the same location as your original remote master. What is it!
source to share