Force Update Of Git Repository

If you have changed or updated a git repository and want to throw away your changes then a good way of forcing the latest changes to run a combination of two commands. The first command is git fetch --all, which tells git to download the latest updates from the remote without trying to merge or rebase anything. This is followed by git reset --hard origin/master where git resets the master branch (assuming you were on the master branch) to become the version of the master branch you just fetched. Here is the two commands in full:

git fetch --all
git reset --hard origin/master

There are a few reasons why you might want to do this but should remember that any changes you have made to files in the repository will be binned in favour of the latest version.

This approach will retain any files that are not part of the git repo so it is useful if you have any non-source controlled configuration files (e.g., database config files) and you want to update the rest of the project around these files. I use this myself on the deployment system of #! code if I want to update one or two files that don't require a major build step. For more serious changes though, I always tag and build the site based on those tags.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
2 + 10 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.