How to get the current branch name in git

610    Asked by MeganHudson in Devops , Asked on Jul 26, 2021

I have some branches in my Git repository. I want to check the current branch name. How can I check that?

Answered by sahin khan

You can run the git branch command in your CMD.

  $ git branch

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

Or, there are several ways to get current branch name in Git:

git-branch.

 We can use the --show-current option of the git-branch command to print the current branch's name.

git-rev-parse.

 Another plausible way of retrieving the name of the current branch is with git-rev-parse.

  git-symbolic-ref.

git-name-rev.



Your Answer

Interviews

Parent Categories