Skip to content

Instantly share code, notes, and snippets.

@SomajitDey
Last active April 21, 2021 07:02
Show Gist options
  • Save SomajitDey/3a438669bd00bdf3b80e4471c2c41a98 to your computer and use it in GitHub Desktop.
Save SomajitDey/3a438669bd00bdf3b80e4471c2c41a98 to your computer and use it in GitHub Desktop.
Why updating a file in GitHub repo or updating a Gist through REST API is faster than git-push

Updating a Gist or file using API is much faster (almost 3 times) than git-push

Git-push takes a lot of work figuring out what files need to be pushed. The local copy also needs to query upstream about its current state before it can decide whether a pull is necessary before push.

A local commit, on the other hand, takes almost no work compared to git-push.

Because Gist / file update using the REST API is nothing but a file-ransfer over https + a local commit@upstream, it is supposed to be faster than git-push.

Git-fetch is faster than git-push and is also better than download using API

Git-fetch doesn't care about the state of the local repo. It's only job is to update the local remote-tracking branch. Hence it is much less involved compared to git-push. In addition, most ISPs provide more download speed than upload. Therefore, git-fetch is always much faster than git-push.

However, there might not be any real benefit in downloading a file using github-API and curl instead of git-fetch. Rather, git-fetch would undoubtedly be faster in case multiple commits need to be downloaded, because of the compression (packfile) done by git-fetch. Also, keep in mind that git:// is faster than https://.

The ideal recipe for speed when dealing with with github gists and repos

So the ideal recipe for speed is:

  • If only one file need to be changed per push, then push using API.
  • Fetch using git-fetch. Use git:// in the fetch-url, if possible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment