Skip to content

Force “git pull” to overwrite local files

G19th June 2019

CNo Comments

TGit

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!

Have your say:

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.