How to clone all remote branches in Git?

后端 未结 30 2630
情话喂你
情话喂你 2020-11-22 01:08

I have a master and a development branch, both pushed to GitHub. I\'ve cloned, pulled, and fetched, but I re

30条回答
  •  余生分开走
    2020-11-22 01:52

    None of these answers cut it, except user nobody is on the right track.

    I was having trouble with moving a repo from one server/system to another. When I cloned the repo, it only created a local branch for master so when I pushed to the new remote, only master branch was pushed.

    So I found these two methods VERY useful. Hope they help someone else.

    Method 1:

    git clone --mirror OLD_REPO_URL
    cd new-cloned-project
    mkdir .git
    mv * .git
    git config --local --bool core.bare false
    git reset --hard HEAD
    git remote add newrepo NEW_REPO_URL
    git push --all newrepo
    git push --tags newrepo
    

    Method 2:

    git config --global alias.clone-branches '! git branch -a | sed -n "/\/HEAD /d; /\/master$/d; /remotes/p;" | xargs -L1 git checkout -t'
    git clone OLD_REPO_URL
    cd new-cloned-project
    git clone-branches
    git remote add newrepo NEW_REPO_URL
    git push --all newrepo
    git push --tags newrepo
    

提交回复
热议问题