How to fetch Git commits by small batches

692 views Asked by At

Is it possible to fetch a remote repository without fetching all the commits that are missing but let say by batches of 100 commits?

I have a repository on my computer which is used as a reference for other repositories to speed up deploy time. Unfortunately, I didn't update it for a while and it's not in sync with the remote repository. GitHub is terribly slow (40-50kbps) and I have around ~150mb to download. This is even less funny when Git stops downloading at 81%....

Is there a way to reduce the quantity of commits to fetch? I was thinking to use the --depth argument but I don't have a shallow Git repository and I don't want it to become one. Also the --depth doesn't seem to work as a fetch commits from this date to this date (which would be also nice). So I could fetch commits day by days if possible.

The problem is that when fetch fails, I have to restart from where I was before starting a fetch. I'd like to be able to fetch smaller chunks so if it fails, I won't have to download 150mb again and again at low speed.

1

There are 1 answers

1
Scott Weldon On

I second @Vampire's suggestion to try switching protocols if you can; I have found that SSH is much more reliable than HTTPS for transferring Git data.

AFAIK, it is not possible to list the commits in the remote repository (you can only get the latest SHA for a given branch). (If it were, then I would have just modified my answer to "How to set a maximum commit count on git push".) However, if you have a commit SHA handy, you can specify the commit to download with:

git fetch origin 96de5297df870:refs/remotes/origin/master

(This will update your origin/master tracking branch to point to that commit.)

Since your code is hosted on GitHub, I recommend you inspect the log on GitHub, and fetch specific commits like this until you are up to date. Also, rather than fetching a set amount of commits at a time, I suggest that you bisect the commits to figure out how many you can download at once.