Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

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!

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.