git - 如何获得默认分支? [英] git - how to get default branch?

查看:174
本文介绍了git - 如何获得默认分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队在dev和master之间交替使用,作为几个repos的默认分支,我想编写一个脚本,在进入目录时检查默认分支。 p>在这些回购协议中的某些回复中,当拉取请求被打开时,它们会默认为'dev'或'master'作为合并目标。

我知道如何设置信息但无法检索:
https://help.github。 com / articles / setting-the-default-branch /

是否有git命令可用于确定远程存储库的默认分支?

解决方案

使用git 2.9.4测试(但可能适用于其他版本)从Github克隆的回购:

  $ git symbolic-ref refs / remotes / origin / HEAD | sed's @ ^ refs / remotes / origin / @@'
master


My team alternates between usage of dev and master as default branch for several repos and I would like to write a script that checks for the default branch when entering a directory.

When pull requests are opened in some of these repos, they either default to 'dev' or 'master' as the merge target.

I understand how to set this information but not retrieve it: https://help.github.com/articles/setting-the-default-branch/

Is there a git command available to determine default branch for remote repository?

解决方案

Tested with git 2.9.4 (but possibly works in other versions) in a repo cloned from Github:

$ git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'
master

这篇关于git - 如何获得默认分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆