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

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

问题描述

我的团队交替使用 dev 和 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.

在其中一些存储库中打开拉取请求时,它们默认为dev"或master"作为合并目标.

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

我了解如何设置此信息但无法检索它:https://help.github.com/articles/setting-the-default-分支/

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

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

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

推荐答案

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

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天全站免登陆