克隆特定分支
要克隆儲存庫的特定分支,請在儲存庫 URL 之前鍵入 --branch <branch name>:
git clone --branch <branch name> <url> [directory]
要使用 --branch 的簡寫選項,請鍵入 -b。此命令下載整個儲存庫並檢出 <branch name>。
要節省磁碟空間,你可以克隆歷史記錄,僅使用單個分支:
git clone --branch <branch_name> --single-branch <url> [directory]
如果未將 --single-branch 新增到命令中,則所有分支的歷史記錄將被克隆到 [directory] 中。這可能是大型儲存庫的問題。
要稍後撤消 --single-branch 標誌並獲取其餘的儲存庫使用命令:
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin