Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
in DevOps and Agile by (29.3k points)

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

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

The scenario is this: I have a post-update hook script on the CENTRAL repo that automatically accesses the test and lives 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.

The problem is this: 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 inevitable.

What I would like to have happened is this: I want the pull from the live and test sites to always overwrite/merge on the pull. Always. These repos will be pull-only as they are not for development.

In all my research, I cannot find a good solution to have a pull always force an overwrite of the local files. Is this at all possible? It would make for a great development scenario if so.

1 Answer

+1 vote
by (19.4k points)

The ideal way to do this is not by using pull but instead, you could fetch and reset:

The following commands will help you to overwrite everything.

git fetch origin master

git reset --hard FETCH_HEAD

git clean -df

You can alter master to any branch 

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

 This way is ideal and more helpful to overwrite everything that you need to pull. And also you can use different options for cleaning depends on the system.

Browse Categories