tags:

views:

114

answers:

2

I am using git for source control and push my changes to a repository on a server on the internet for safe keeping.

I can do some small amounts of coding on a laptop on a train, which has a wifi internet connection but it's not that reliable and occasionally drops out or becomes unusable slow. My question is what happens if my connection is lost during a "git push"? Will I end up with a corrupted or half updated git repository? And if so, how difficult is it to recover it?

+5  A: 

According to Linus git is so well secured on the data area that it would even detect a memory error on the system it's running on. It will simply not apply the packets that arrive at the server that have an invalid checksum, so you have nothing to worry about.

Blizz
If I have several local changes to push can I be sure that it won't apply some of them but not others?
John Burton
+7  A: 

Git will not corrupt or "half update" your Git repository just because of a failed or slow connection. It's very robust and I would still feel comfortable using it even in the most arduous circumstances.

The actual push function is implemented in essentially two steps (in the case of a fast-forward push, which should always be the case):

  • upload all objects reachable from your current branch head and not reachable from the remote branch head
  • update the remote branch head to point to the latest commit

The first operation is idempotent, so if it fails for any reason halfway through, you can simply run it again to get everything up to date. The second operation is atomic and only happens once all the new objects are uploaded.

Greg Hewgill