in Technology by
How to get the current branch name in Git?

1 Answer

0 votes
by
 
Best answer
git branch

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

or with Git 2.22 and above:

git branch --show-current

Related questions

0 votes
    What is the difference between git checkout [branch name] and git checkout -b [branch name]?...
asked Nov 4, 2020 in Technology by JackTerrance
0 votes
    I know that the name of the user account can be retrieved from the built in variable User!UserID but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    How to rename and remove branch in remote Git?...
asked Aug 24, 2021 in Technology by JackTerrance
0 votes
    How can we create a remote Git branch?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    How to push a new local branch to a remote Git repository and track it too?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    How can we check out a remote Git branch?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    How can we rename a local Git branch?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    How git replace with origin branch?...
asked Dec 10, 2020 in Technology by JackTerrance
0 votes
    My git workspace is dirty, there are some local modifications. When I use the command git pull origin master it ... Ansible git module? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I created a local branch that I want to 'push' upstream. There is a similar question here on Stack ... the upstream repository? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I don't want to rename a remote branch, as described in the Rename master branch for both local and remote ... and remote branch name Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    What is the Git command to move branch pointer to different commit without checkout? A. Git cherrypick B. Git update-ref C. Git reset head...
asked Dec 24, 2022 in Technology by JackTerrance
0 votes
    What is the Git command to create a branch? A. git invoke branch branchname B. git add branch branchname C. git create branch branchname D. git branch branchname...
asked Dec 20, 2022 in Technology by JackTerrance
0 votes
    Move the most recent commit(s) to a new branch with Git?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    Can you recover a deleted branch in Git?...
asked Nov 4, 2020 in Technology by JackTerrance
...