一次创建几个git分支

问题描述 投票:0回答:2

如果我在master分支中并且想要创建另一个名为myAwesomeBranch的分支但是没有检查它,我会这样做:

git branch myAwesomeBranch

我想在master的一个命令中创建几个分支,这可能吗?

我尝试过:

git branch myAwesomeBranch1 myAwesomeBranch2 myAwesomeBranch3

但它没有用。

git
2个回答
0
投票

enter image description here图片来源:https://www.lynda.com/Git-tutorials/Delete-local-remote-branches/664821/719158-4.html


Git不支持git branch <multiple branches>

正确的方法是使用shell脚本(单行也会这样做)

# loop over the branch list you wish to create
for branchName in {b1,b2,b3}; 

    # Create the branch
    do git branch $branchName; 

    # Set the upstream so you will be able to push the branch to the remote
    git branch --track $branchName origin/$branchName

done

3
投票

或者,您可以使用“;”在一行中创建多个分支(使用多个命令)

git branch myAwesomeBranch1; git branch myAwesomeBranch2; git branch myAwesomeBranch3

© www.soinside.com 2019 - 2024. All rights reserved.