How to git fetch efficiently from a shallow clone

前端 未结 5 632
长情又很酷
长情又很酷 2020-11-27 03:53

We use git to distribute an operating system and keep it upto date. We can\'t distribute the full repository since it\'s too large (>2GB), so we have been using shallow clon

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 04:44

    I don't know if it suites your set-up but what I use is to have ha full clone of a repo in a separate directory. Then I do shallow clone from the remote repository with reference to the local one.

    git clone --depth 1 --reference /path/to/local/clone git@some.com/group/repo.git 
    

    That way only the differences with the reference repository and remote are actually fetched. To make it even quicker you can use the --shared option, but be sure to read about the restrictions in the git documentation (it can be dangerous).

    Also I found out that in some circumstances when the remote has changed a lot, the clone starts fetching too much data. It is good to break it then and update the reference repo (which strangely takes much less bandwidth than it took in the first place.) And then start the clone again.

提交回复
热议问题