I\'m pushing a large file to git, but have a very slow connection. What is the safest way to terminate this push (mid-push), and resume it when I have a better connection?
I believe git push
is atomic, meaning that if you just Ctrl-C out of the operation, the remote repository will be in its original state, prior to the push. This also means that, when you do the push again, it will be starting over from the beginning. But it doesn't sound like that's necessarily a problem for you.
Killing the client (Ctrl+C or any other method) won't cause the data on the server to be corrupted, if that's what you mean by "safe". The server doesn't update anything until all the blobs are transferred successfully, then it updates the refs to point to the new blobs.
Git doesn't have any facilities to resume an interrupted transfer though, so you'll probably have to transfer the big blob again when you have a faster connection.
Before Git 2.30 (Q1 2021), "git push"(man) that is killed may leave a pack-objects process behind, still computing to find a good compression, wasting cycles.
This has been corrected and illustrates how safe it is to kill a push in progress.
See commit 8b59935 (20 Nov 2020) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit adae5df, 03 Dec 2020)
send-pack: kill pack-objects helper on signal or exit
Signed-off-by: Jeff King
We spawn an external pack-objects process to actually send objects to the remote side.
If we are killed by a signal during this process, the pack-objects will keep running and complete the push, which may surprise the user.We should take it down when we go down.