Adjusting My Work Habits to Cope with git
I had switched to using git after I b0rked one of my projects mercurial repository. It has been problem free so far. But one git oddity bit me in the ass just now. git does not update a remote repository if it is attached to a working directory (non-bare repository in git terms). I found this a bit odd because all of the DVCS that I had used, bzr, darcs, mercurial, they would all update the remote repository if you pushed your changes. git does not do this. I found a thread on the git mailing list and it looks like there had been long debates with regards to this behavior. It also looks like the current behavior will remain unchanged. Worse still, if you do a commit on the remote repo, you will effectively undo that changes made by the last push!
It’s puzzling for someone who came from other DVCS such as darcs and mercurial. I was always under the impression that updating the remote repo when doing a push was the right thing to do.
I found the answer in the git FAQ:
The
pushoperation is always about propagating the repository history and updating the refs, and never touches the working tree files. In particular, if you push to update the branch that is checked out in a remote repository the files in the work tree will not be updated.This is a precautionary design decision. The remote repository’s work tree may have local changes, and there is no way for you, who are pushing into the remote repository, to resolve conflicts between the changes you are pushing and the ones in the work tree…
Which is absolutely right! I can’t recall how many times I have been hit with this problem. I make changes to the remote repo and commit them. Meanwhile I make changes to the clones, thinking the changes will also benefit the remote repo, I do a push and POOF! conflicts during merge.
I think git’s behavior makes more sense and it’s just a simple matter of remembering to do git reset --hard HEAD on the remote repo to bring the working directory up to date.
