Difference between revisions of "Git Tricks"

From Aram's Wiki
Jump to: navigation, search
(Created page with "== Clone remote repository using local cache == Let's say you want a new clone of a git repository, for example <code>https://go.googlesource.com/go</code>, but you already h...")
 
(References)
 
(4 intermediate revisions by the same user not shown)
Line 8: Line 8:
  
 
This will work even if <code>$HOME/go</code> doesn't exist.
 
This will work even if <code>$HOME/go</code> doesn't exist.
 
== References ==
 
 
* [https://git-scm.com/docs/git-clone git-clone(1)]
 
  
 
== Only clone a specific branch ==  
 
== Only clone a specific branch ==  
Line 20: Line 16:
  
 
  git clone --single-branch -b release-branch.go1.17 --no-tags https://go.googlesource.com/go go.test
 
  git clone --single-branch -b release-branch.go1.17 --no-tags https://go.googlesource.com/go go.test
 +
 +
== References ==
 +
 +
* [https://git-scm.com/docs/git-clone git-clone(1)]
 +
* [https://git-scm.com/docs/git-replace git-replace(1)]
 +
* [https://git-scm.com/docs/git-checkout git-checkout(1)]
 +
* [https://stackoverflow.com/q/59719412 Under what circumstances will git replacements be pushed/pulled?]
 +
* [https://stackoverflow.com/q/5724522 Creating a GitHub repository with only a subset of a local repository's history]

Latest revision as of 13:46, 20 September 2021

Clone remote repository using local cache

Let's say you want a new clone of a git repository, for example https://go.googlesource.com/go, 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 https://go.googlesource.com/go 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 https://go.googlesource.com/go go.test

And if you don't want tags either:

git clone --single-branch -b release-branch.go1.17 --no-tags https://go.googlesource.com/go go.test

References