如何从命令行/终端获取主分支名称?
我知道默认情况下主分支称为master
,但是可以将其重命名为任何他们想要的东西。
PS-获得本地和远程主分支的名称会很好。
编辑:我称之为main branch
其他人可能会称之为default branch
或stable branch
。这是你应该把所有东西(稳定/工作)融入其中的那个。
你可能想要使用这个命令git branch -r
,-r
仅用于列表远程分支,如果你想列出两个使用-a
。通常主分支指向origin/HEAD
这样的origin/HEAD -> origin/master
我对git
一无所知,但是,在git
,通常有{remote}/HEAD
,例如origin/HEAD
。 man page of git remote
。以下是 set-head
Sets or deletes the default branch (i.e. the target of the
symbolic-ref refs/remotes/<name>/HEAD) for the named remote.
Having a default branch for a remote is not required, but allows
the name of the remote to be specified in lieu of a specific
branch. For example, if the default branch for origin is set to
master, then origin may be specified wherever you would normally
specify origin/master.
的摘录:
{remote}/HEAD
据我所知,{remote}
是# With "remotes/"
git branch -r | grep -Po "HEAD -> \K.*$"
remotes/origin/master
# Without "remotes/"
git branch -r | grep -Po "HEAD -> remotes/\K.*$"
origin/master
的主要/默认分支。有人可以使用这个得到分支的名称(有没有人知道更好的/管道命令?):
HEAD
当想要获得本地主/默认分支时,通常没有{remote}/HEAD
分支,但通常只有一个跟踪git branch -vv | grep -Po "[ *gb]*\K[^ ]*(?=[ ][ 0-9a-f]* \[$(git branch -r | grep -Po "HEAD -> \K.*$"))"
master
的分支,我们可以使用哪个名称(同样,肯定有更好的命令):
qazxswpoi