Have you ever tried cloning a Git project for more than three hours? I’ve felt… Sorrow is so great (; ´ ༎ ຶ Д ༎ ຶ `)
I didn’t think it was my problem, so I asked my senior colleagues: why couldn’t I clone the project for three hours? Is there a faster way?
In the end! Git clone depth=1
Depth Specifies the clone depth. A value of 1 indicates that only the latest COMMIT is cloned.
That’s it
git clone https://github.com/xxxx.git --depth=1
Copy the code
This approach clones projects that contain only a branch of the most recent commit and are small enough to solve the problem of cloning too slowly or stopping projects that are too large.
But this creates another problem. It just clone the default branch (usually the master branch).
Other remote branches are not local.
If we wanted to clone only the last COMMIT for a given branch, we could use the following command
Git clone - the depth of 1 - branch branch name https://github.com/xxxx.gitCopy the code
If we want to clone other remote branches (such as master) locally, we can use the following command
Git clone - the depth 1 https://github.com/dogescript/xxxxxxx.git git remote set - branches origin branch name git fetch - the depth of 1 Git Checkout Branch nameCopy the code
Of course, if your project needs to switch branches frequently, it is better to clone all of them