[英]git branch for multiple remotes
运行git branch -r
我在远程存储库上看到了分支。 有没有办法在同一工作目录中查看多个存储库的分支? 我的目标是创建一个文件,该文件列出几个存储库中的所有分支,如下所示:
repo1:master,dev,qa,fy-2473
repo2:master,dev,fy-1128,staging
repo3:master,fy-1272,staging
等等等等。 我有这个以正确的方式打印分支:
git branch -r | awk -F' +|/' -v ORS=, '{if($3!="HEAD") print $3}' >> repolist.txt
我只需要将此功能与几个存储库一起使用,而不必为此复制每个存储库。 谢谢。
您可以使用git remote add name url将存储库添加到同一工作目录,然后在执行git branch -r
时将看到所有存储库。
例如:
git remote add repo1 http://github.com/example/foo.git
git remote add repo2 http://bitbucket.com/example/bar.git
git fetch --all
git branch -r
将列出:
repo1/master
repo1/dev
repo2/master
repo2/featureXYZ
使用git remote add
将您的仓库作为远程仓库添加到本地仓库,然后使用git fetch --all
它们并修改您的awk命令以产生所需的结果。
此命令将产生您期望的输出
git branch -r | awk '
# split remote and branch
{
remote = substr($1, 0, index($1, "/") - 1)
branch = substr($1, index($1, "/") + 1)
}
# eliminate HEAD reference
branch == "HEAD" { next }
# new remote found
remote != lastRemote {
# output remote name
printf "%s%s:", lastRemote ? "\n" : "", remote
lastRemote = remote
# do not output next comma
firstBranch = 1
}
# output comma between branches
!firstBranch { printf "," }
firstBranch { firstBranch = 0 }
# output branch name
{ printf branch }
# final linebreak
END { print "" }
'
或单线无评论
git branch -r | awk '{ remote = substr($1, 0, index($1, "/") - 1); branch = substr($1, index($1, "/") + 1) } branch == "HEAD" { next } remote != lastRemote { printf "%s%s:", lastRemote ? "\n" : "", remote; lastRemote = remote; firstBranch = 1; } !firstBranch { printf "," } firstBranch { firstBranch = 0 } { printf branch } END { print "" }'
运行git remote add
添加所有远程存储库,并运行git fetch
检索/更新远程存储库信息后, git branch -a
将显示所有远程和本地分支。 对于远程分支机构,它将以以下格式显示:
remotes/{remote_name}/{branch_name}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.