Ashwin
Ashwin

Reputation: 61

What is git doing when I push a commit to remote?

I'd like to understand, at a granular level, what is going on on behind the scenes when I push a commit to a remote repository. I get the following terminal output for a simple one-line change:

1 file changed, 1 insertion(+), 1 deletion(-)
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 510 bytes | 510.00 KiB/s, done.
Total 6 (delta 5), reused 0 (delta 0), pack-reused 0
remote: Analyzing objects... (6/6) (421 ms)
remote: Storing packfile... done (97 ms)
remote: Storing index... done (47 ms)
To vs-ssh.visualstudio.com:v3/{...}
 * [new branch]      {...} -> {...}

What do each of these lines mean? Some of this appears to be specific to VS Code as well, which lines are those?

Upvotes: 0

Views: 140

Answers (1)

Schwern
Schwern

Reputation: 164859

None of it is specific to VS Code.

Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 510 bytes | 510.00 KiB/s, done.
Total 6 (delta 5), reused 0 (delta 0), pack-reused 0

This is git gc (Garbage Collection) cleaning and optimizing and compressing your repository. Originally there were 11 objects, now there are 6. That's not really relevant to pushing so I'll skip it.

remote: Analyzing objects... (6/6) (421 ms)
remote: Storing packfile... done (97 ms)
remote: Storing index... done (47 ms)
To vs-ssh.visualstudio.com:v3/{...}
 * [new branch]      {abc123} -> {def456}

This is the push.

Because two commits with the same ID have the same content and the same history, Git doesn't have to do any complicated calculations to figure out what to push. It just looks back through your branch until it finds a commit ID in common with the remote.

Your local repository has to send all the new objects to the server: blobs (the content of files), trees (the filenames, directories, and permissions), and commits. There are six of these objects.

It could do this one at a time, and that is the default, but that's inefficient. Since you're talking to a "smart" Git server, it creates and sends a packfile. A packfile is all the objects compressed in a single file, and the index for that packfile. The remote lines are the remote server telling you what its doing and how long it took.

Finally you get a summary. To the remote vs-ssh.visualstudio.com:v3/{...} you sent a new branch which starts at commit abc123 and ends at def456.

Upvotes: 2

Related Questions