How do I clone a single branch in Git?

后端 未结 21 2996
再見小時候
再見小時候 2020-11-22 00:09

I have a local Git repository called \'skeleton\' that I use for storing project skeletons. It has a few branches, for different kinds of projects:

casey@aga         


        
21条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 00:39

    You can try the long-winded way:

    mkdir newrepo.git
    cd newrepo.git
    git init
    git remote add origin file:///path/to/original
    git fetch origin branchiwant:refs/remotes/origin/branchiwant
    git checkout -b branchiwant --track origin/branchiwant
    

    What this does is:

    • Create and init an empty Git repository.
    • Adds the original repository as a remote called origin.
    • Fetches only the branch you require from the remote called origin.
    • Creates and checks out a new branch that is set up to track the source branch you just cloned.

    Hopefully that will be something like what you are after.

提交回复
热议问题