How to use git shallow cloning to improve performance
Cloning the entire warehouse is a standard operation using GIT. Each clone typically includes everything in the repository.
This means that when cloning, you will get not only files, but also each revision of each file that has been submitted and the history of each submission. Moreover, if you have many assets in your code base, it will have a long history. The main problem is that this will create bottlenecks in the continuous integration (CI) pipeline.
View GitHub COM and other code base optimization projects often need to clone the code. The more star projects, the larger the amount of code and the longer the history. In the case of poor domestic network, the network is often disconnected after downloading several GB. Once interrupted, can not continue, and have to start from scratch, miserable.
Of course, you can download the zip / GZ distribution source package, but if you want to participate in the project development, this scheme is not feasible.
Solution: git shallow clone
Git shallow cloning allows you to get only the latest submissions, not the entire repurchase history. Therefore, if your project has a history of many years or thousands of submissions, you can select a specific depth for extraction.
How to perform a git shallow clone
Provide the parameter — depth 1 in the GIT clone command to copy only the latest version of the warehouse:
git clone -–depth [depth] [remote-url]
You can also use git clone to access a single branch:
Git clone [remote url] - Branch [name] - single branch [folder]
With git shallow cloning, you can get fewer files. Cloning, building, and feedback can be done quickly and delivered faster.
Solution: completely delete unnecessary history
If you do not need to maintain a complete history, you can completely delete the history from the GIT repository using the following command set. After cloning the repository to a path on the workstation, use
--orphanOption, which returns it to the init state with only one commit.
How to trim your repository
git checkout --orphan freshBranch git add -A git commit git branch -D master git branch -m master git push -f origin master git gc --aggressive --prune = all git push -f origin master
Add all files in the path and submit. Next, delete the remote main branch and rename the current branch to master. The new master server is then forced into the code hosting environment. Finally, use the prune command to delete all old files, and then push the new state to the remote.
By pruning your repository, you can improve clone performance without using git shallow clones. Eliminating unwanted history can reduce the burden on your repository, resulting in faster delivery.
Do you want to reset the local repository? You can also use
git force cloneCompletely overwrite your history. But be careful. This will destroy your local unpublished modifications.