How do I clone a single branch in Git?

后端 未结 21 2595
再見小時候
再見小時候 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:48

    A little late but I wanted to add the solution I used to solve this problem. I found the solution here.

    Anyway, the question seems to be asking 'how to start a new project from a branch of another repo?'

    To this, the solution I used would be to first create a new repo in github or where ever. This will serve as the repo to your new project.

    On your local machine, navigate to the project that has the branch you want to use as the template for your new project.

    Run the command:

    git push https://github.com/accountname/new-repo.git +old_branch:master
    

    What this will do is push the old_branch to new-repo and make it the master branch of the new repo.

    You then just have to clone the new repo down to your new project's local directory and you have a new project started at the old branch.

提交回复
热议问题