How to clone a snapshot of a remote repository at a specific branch?
Posted on In QAI know that one can make a zip of the current branch by:
git archive -o archive.zip HEAD
However, at situations, one may want to clone a copy/snapshot of remote repository at a specific branch because:
1) The repository is large with long history and cloning the whole history takes too much time.
2) What I want is a specific branch’s “snapshot” not the master branch’s.
To take a snapshot (no history, only files at HEAD) from branch br1 from git@git.example.com:repo:
git clone -b br1 git@git.example.com:repo --depth 1
-b br1
makes git clone the branch br1.
--depth 1
makes git only fetch the history of depth 1