GIT: Force Overwrite of Local File with Remote File

Apr 10, 2021 min read

Sometimes we just need to reset a local file with what is saved in a remote repository. For example, you’re working locally and your files just get into a place where you need to reset, maybe only a file or two. Maybe you’ve merged in another branch and there are numerous conflicts and you just want whatever the remote branch has, whatever the reason, here are a few commands you can use.

Overwriting a single file

Update your local version of the remote repository, i.e. Origin

git fetch

Checkout the file(s) you want to overwrite

git checkout origin/<remote branch name> <filepath>

Example:

git checkout origin/dev server.js

If you want to overwrite ALL changes you can use the reset command

git fetch
git reset --hard origin/<remote branch name>