Force “git pull” to overwrite local files
I needed to over-write a local version of a repository as it was not fully updating. This worked.
To force Git to download the latest version of a GitHub repository and overwrite all local files, enter the following command:
git fetch --all
If updating from the master branch, enter:
git reset --hard origin/master
Otherwise enter:
git reset --hard origin/<branch_name>
The git fetch
function downloads the latest files from GitHub without trying to merge or rebase anything.
The git reset
resets the master branch to what was just fetched. The --hard
option changes all the files in the working tree to match the files in origin/master
.
Note: This will likely overwrite any local changes, so these steps should only be used when absolutely necessary.
Comments
No comments have yet been submitted. Be the first!