Git Hub Clone All Branches At Once

2020-02-16 06:34发布

I'm trying to clone an entire repository onto my machine using linux. I used

git clone <url>   

I then went into the folder where it was downloaded and typed

git branch 

in the terminal. It's only showing me master and not other branches which were in the remote repository. How do I clone all branches?

I know that for each branch in the remote I can separately use

git checkout -b <name of local branch> origin/<name of remote branch>

but is there any way other than that?

标签: git github
7条回答
混吃等死
2楼-- · 2020-02-16 07:36

(1) Inside git local repostitory, create a new sh file

touch getAllBranches.sh
vi getAllBranches.sh

(2) Insert the below content to getAllBranches.sh file:

for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
   git branch --track ${branch#remotes/origin/} $branch
done

(3) Get all branches:

chmod +x getAllBranches.sh    
sh getAllBranches.sh

(4) Check result at local repository:

git branch

For example, I use repository: https://github.com/donhuvy/spring-boot

As you can see, I have been fetched all branches to local machine:

enter image description here

查看更多
登录 后发表回答