如何在 Git 中获取当前分支名称? [英] How to get the current branch name in Git?

查看:90
本文介绍了如何在 Git 中获取当前分支名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Subversion 背景,当我有一个分支时,我知道我在做什么,这些工作文件指向这个分支".

I'm from a Subversion background and, when I had a branch, I knew what I was working on with "These working files point to this branch".

但是使用 Git 时,我不确定在 NetBeans 或 Notepad++ 中编辑文件时,它是绑定到 master 还是另一个分支.

But with Git I'm not sure when I am editing a file in NetBeans or Notepad++, whether it's tied to the master or another branch.

git 在 bash 中没有问题,它告诉我我在做什么.

There's no problem with git in bash, it tells me what I'm doing.

推荐答案

git branch

应该显示你的 repo 的所有本地分支.加星标的分支是您当前的分支.

should show all the local branches of your repo. The starred branch is your current branch.

如果你只想检索你所在分支的名称,你可以这样做:

If you want to retrieve only the name of the branch you are on, you can do:

git rev-parse --abbrev-ref HEAD

或使用 Git 2.22 及更高版本:

or with Git 2.22 and above:

git branch --show-current

这篇关于如何在 Git 中获取当前分支名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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