tags:

views:

93

answers:

3

I have repository on GitHub to which I commit regularly from my local computer. On the other side I have server pulling from the repository. The web server just executes a git pull in order to get the latest changes from the GitHub repository. This is completely automated and should stay that way (solutions like the Ruby Tool Capistrano are out).

A simple git pull usually works just fine. However, sometimes I change the last commit (git commit --amend) and git push the changes twice to GitHub. If the server auto-updated it's code between the two pushes to GitHub, the next server side git pull fails because there is merge conflict.

To solve this problem I need the following behavior: The server should continue to git pull (or something equivalent) the GitHub repository but in case of a merge conflict, the GitHub repository should just take precedence over the local repository on the server. So, I want a git command that behaves like git clone, but doesn't copy the whole repository every single time.

+6  A: 

You can of course do the forced git checkout if you don't do any local modifications there, but the right answer would be to never ever amend commits that have left your local repository.

Michael Krelin - hacker
I know, but I guess it doesn't matter since I'm currently the only user of that remote repository.
Christoph Schiessl
But now you see it does matter. Because the other computer is also a user. But now that you put the question this way — does it mean that you're asking how to resync it once?
Michael Krelin - hacker
There's nothing wrong with amending commits if only one *person* is working with the repositories (no matter how many repos there are). Unless that person is concerned about confusing him/herself, they can always do checkouts, resets, or forced updates to get multiple repos back in sync.
Dan Moulding
Dan, this question exactly demonstrates what's wrong with amending commits in one-man-repo. Exactly confusing the hell out of himself and his computers ;-). I'd say *there's nothing wrong with amending commits as long as you are aware of implications and are ready to deal with them*.
Michael Krelin - hacker
Give a man a fish, or teach him to fish? Telling him not to amend his commits is like giving him the fish... I'd rather he learn :)
Dan Moulding
@hacker: The real danger I see with amending commits is with amending a commit that someone else has begun using as a base upon which to do their own work. That will certainly lead to a confusing situation that will require careful attention and merging. But if you're working alone, this usually won't be a problem.
Dan Moulding
I think it's cleaner to use amend sometimes, and when you are working alone there is no problem. I understand that it could be problem if are working with a team or in an Open Source environment, but that's not the case here. A clean history is worth something too, right? The reason I use amend is that I don't want to have extra commits just to fix a misspelled comment in the source code.
Christoph Schiessl
Dan, it takes time to learn to fish and it hard to go this route hungry ;-)Christoph, it is cleaner to use amend, but you should normally have enough time for amendments before the code leaves your repository.But then again — as long as you know how to deal with it, it's just fine and you're the one to decide whether you do or don't want to amend.
Michael Krelin - hacker
+3  A: 

I you never modify the sources you pull, what you probably want to do is just fetch then checkout.

JB
+5  A: 

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

Instead of having the server automatically run git pull, you should have it run git fetch origin; git checkout origin/master. Of course, this assumes that you've got the "origin" remote set up to refer to your local computer's repo.

If you ever need to modify the server sources directly (for a quick fix, or whatever) and want to commit those changes, you can git branch -f master origin/master before you do the commit to get the server's master branch set to the same commit as the local computer's branch.

Dan Moulding
I'm going to try that.
Christoph Schiessl