Git – force a pull to overwrite everything, on every pull


I have a CENTRAL bare repo that has 3 developer repositories pulling and pushing to it normally.

I also have 2 other repositories that pull from the CENTRAL bare repo: one is the live server and the other is a test/stage server, each pulling their own respective branch.

The scenario is this: i have a post-update hook script on the CENTRAL repo that automatically accesses the test and live repos and runs a pull command on each. this updates both test and live servers, all depending on what branch has new commits. This all works great.

There may be times in an emergency that files may be directly updated on the server (via ftp or whatever) and the CENTRAL post-update script will then fail since merge/overwrite conflicts will occur. There is no way to avoid this scenario and it is eventual.

I want the pull from the live and test sites to ALWAYS overwrite/merge on pull. ALWAYS. These repos will be pull-only as they are not for development.


Really the ideal way to do this is to not use pull at all, but instead fetch and reset:

git fetch origin master
git reset –hard FETCH_HEAD
git clean -df
(Altering master to whatever branch you want to be following.)

pull is designed around merging changes together in some way, whereas reset is designed around simply making your local copy match a specific commit.

You may want to consider slightly different options to clean depending on your system’s needs.