How to force check for the latest version from a remote server?

I have a repository on GitHub that I regularly commit from my local machine. On the other hand I have a server pulling from a repository. The webserver just executes git pull

to get the latest changes from the GitHub repository. This is fully automated and should remain that way (there are no solutions like Capistrano's Ruby Tool).

Simple git pull

usually works fine. However, sometimes I change the last post ( git commit --amend

) and git push

change twice on GitHub. If the server automatically refreshes code between two pushes on GitHub, the next server side git pull

fails because there is a merge conflict.

To solve this problem, I need the following behavior: the server should continue git pull

(or something similar) to the GitHub repository, but in case of a merge conflict, the GitHub repository should take precedence over the local repository to the server. So, I need a git command that behaves like git clone

, but doesn't copy the entire repository every time.

+2


source to share


3 answers


JB to the right, but I'm going to expand on his answer a bit.

Instead of the server git pull

starting automatically , you should start it git fetch origin; git checkout origin/master

. Of course, this assumes that you have an "origin" remote set up to link to the local machine's relay.



If you ever need to directly change the server sources (for a quick fix or whatever) and want to commit those changes, you can git branch -f master origin/master

set the server's master branch to the same commit as the branch before committing. local computer.

+6


source


You can of course do a forced git checkout if you don't make any local changes there, but the correct answer would be to never fix commits that have left your local repository.



+7


source


I never change the sources you pull

are, what you probably want to do is simple fetch

, then checkout

.

+4


source







All Articles