How do I force an overwrite of local files on a git pull
?
The scenario is the following:
It looks like the best way is to first do:
git clean
To delete all untracked files and then continue with the usual git pull
...
Reset the index and the head to origin/master
, but do not reset the working tree:
git reset origin/master
git fetch --all && git reset --hard origin/master && git pull
In speaking of pull/fetch/merge in the previous answers, I would like to share an interesting and productive trick,
git pull --rebase
This above command is the most useful command in my Git life which saved a lot of time.
Before pushing your newly commit to server, try this command and it will automatically synchronise the latest server changes (with a fetch + merge) and will place your commit at the top in the Git log. There isn't any need to worry about manual pull/merge.
Find details in What does "git pull --rebase" do?.
Just do
git fetch origin branchname
git checkout -f origin/branchname // This will overwrite ONLY new included files
git checkout branchname
git merge origin/branchname
So you avoid all unwanted side effects, like deleting files or directories you wanted to keep, etc.
I had the same problem. No one gave me this solution, but it worked for me.
I solved it by:
.git
directory.git reset --hard HEAD
git pull
git push
Now it works.