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.
source to share
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.
source to share