Git single-branch cloning¶
Git single-branch cloning is a Git operation used to copy a repository while limiting the retrieval to a specific branch, rather than cloning all references and history^[600-developer__tools__git__git-command.md].
Usage¶
To perform a single-branch clone, use the --single-branch flag in conjunction with the --branch flag^[600-developer__tools__git__git-command.md]. This allows the user to specify exactly which branch to clone^[600-developer__tools__git__git-command.md].
The syntax for this command is:
git clone --single-branch <repository-url> --branch <remote-branch-name> <local-directory>
For example, to clone only the dev branch from a repository into a local directory named develop^[600-developer__tools__git__git-command.md]:
git clone --single-branch git@github.com:yudady/concurrency.git --branch dev develop
Behavior¶
When this command is executed, Git enumerates, compresses, and receives the objects related to the specified branch^[600-developer__tools__git__git-command.md]. The resulting local clone will contain only the history and files associated with that branch, which can save disk space and reduce cloning time compared to a full repository clone.
Related Concepts¶
- [[Git]]
- [[Branching]]
- [[Version Control]]
Sources¶
600-developer__tools__git__git-command.md