Git Tricks

From Aram's Wiki
Jump to: navigation, search

Clone remote repository using local cache

Let's say you want a new clone of a git repository, for example, but you already have it cloned elsewhere, say $HOME/go and you don't want to download all the objects from the internet, yet you don't want to clone the local repository either — you want the new clone to be connected to the remote repository.

You can do this:

git clone --reference-if-able $HOME/go --dissociate go.test

This will work even if $HOME/go doesn't exist.

Only clone a specific branch

git clone --single-branch -b release-branch.go1.17 go.test

And if you don't want tags either:

git clone --single-branch -b release-branch.go1.17 --no-tags go.test