How do I force an overwrite of local files on a git pull
?
The scenario is the following:
It seems like most answers here are focused on the master
branch; however, there are times when I'm working on the same feature branch in two different places and I want a rebase in one to be reflected in the other without a lot of jumping through hoops.
Based on a combination of RNA's answer and torek's answer to a similar question, I've come up with this which works splendidly:
git fetch
git reset --hard @{u}
Run this from a branch and it'll only reset your local branch to the upstream version.
This can be nicely put into a git alias (git forcepull
) as well:
git config alias.forcepull "!git fetch ; git reset --hard @{u}"
Or, in your .gitconfig
file:
[alias]
forcepull = "!git fetch ; git reset --hard @{u}"
Enjoy!