Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches.
Git prevents you from pulling files to your local machine if any unsaved or untracked changes would be overwritten by the merge operation. You can use the force pull method to force Git to pull the changes you want to receive on your local computer.
The reason for error messages like these is rather simple: you have local changes that would be overwritten by the incoming new changes that a "git pull" would bring in. For obvious safety reasons, Git will never simply overwrite your changes.
Really the ideal way to do this is to not use pull
at all, but instead fetch
and reset
:
git fetch origin master
git reset --hard FETCH_HEAD
git clean -df
(Altering master
to whatever branch you want to be following.)
pull
is designed around merging changes together in some way, whereas reset
is designed around simply making your local copy match a specific commit.
You may want to consider slightly different options to clean
depending on your system's needs.
You could try this:
git reset --hard HEAD
git pull
(from How do I force "git pull" to overwrite local files?)
Another idea would be to delete the entire git and make a new clone.
git reset --hard HEAD
git fetch --all
git reset --hard origin/your_branch
I'm not sure how to do it in one command but you could do something like:
git reset --hard
git pull
or even
git stash
git pull
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With