多个遥控器的git分支

时间:2016-07-06 11:03:30

标签: git git-branch gawk git-remote

运行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

我只需要让这个功能与几个存储库一起工作,而不必为了这个目的而克隆每个和每个存储库。 感谢。

3 个答案:

答案 0 :(得分:2)

您可以使用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

答案 1 :(得分:1)

使用$scope.openClass = function (classes) { $log.info("classes",classes); var modalInstance = $modal.open({ templateUrl: 'classes.html', controller: 'ModalClassInstanceCtrl', resolve: { info: function () { var info = {}; for (var i=0;i<classes.length;i++){ if (classes[i].level==4){ info['name']= classes[i].name; $log.info("classinfo",info); } } $log.info(info); return info; } } }); 将您的repos作为遥控器添加到您的本地仓库,然后git remote add添加,并调整您的awk命令以生成您想要的结果。

此命令将产生您期望的输出

git fetch --all

或作为没有评论的单行

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 "" }
'

答案 2 :(得分:0)

运行git remote add以添加所有远程存储库,并运行git fetch以检索/更新远程存储库的信息后,git branch -a将显示远程和本地的所有分支。对于远程分支,它将以格式显示为:

remotes/{remote_name}/{branch_name}
相关问题