Clone just the stable and one other branch in git?

后端 未结 4 1519
粉色の甜心
粉色の甜心 2020-12-23 10:44

I\'m just getting started with git and I have a question. My app has 10 other developers working on it, each one having their own branch like dev_XXXXX. So if I do a clone o

4条回答
  •  余生分开走
    2020-12-23 11:21

    If you clone, all revisions in all branches are cloned along, but the cloned repository will check out master by default.

    Just taking selected branches is trickier since git does not really think you should work that way. You have to pull down the branches manually:

    mkdir repoclone
    cd repoclone
    git init
    git remote add origin git://remote/url
    git fetch origin master:master
    git fetch origin dev_XXX:dev_XXX
    

    Above is what I knew worked. However, if you want to set up a git repo that works as normal, just has a more narrow view of its remote branches? You can do that pretty easily:

    mkdir repoclone
    cd repoclone
    git init
    git remote add origin git://remote/url
    
    # now open .git/config for editing in your editor
    # replace the following line (grab all remote branches)
    fetch = +refs/heads/*:refs/remotes/origin/*
    
    # replace with lines listing exactly which branches you want
    fetch = +refs/heads/master:refs/remotes/origin/master
    fetch = +refs/heads/dev_XXX:refs/remotes/origin/dev_XXX
    
    # save the file, now run
    
    git fetch
    

提交回复
热议问题