How do I force an overwrite of local files on a git pull
?
The scenario is the following:
Despite the original question, the top answers can cause problems for people who have a similar problem, but don't want to lose their local files. For example, see Al-Punk and crizCraig's comments.
The following version commits your local changes to a temporary branch (tmp
), checks out the original branch (which I'm assuming is master
) and merges the updates. You could do this with stash
, but I've found it's usually easier to simply use the branch / merge approach.
git checkout -b tmp
git add *; git commit -am "my temporary files"
git checkout master
git fetch origin master
git merge -s recursive -X theirs origin master
where we assume the other repository is origin master
.