0
0
GitHow-ToBeginner · 3 min read

How to See Current Branch in Git: Simple Commands

To see the current branch in Git, use the command git branch which lists all branches and highlights the current one with an asterisk (*). Alternatively, git status also shows the current branch at the top of its output.
📐

Syntax

The main commands to check the current branch are:

  • git branch: Lists all branches and marks the current branch with an asterisk (*).
  • git status: Shows the current branch along with the working directory status.
bash
git branch

git status
💻

Example

This example shows how to use git branch to find the current branch. The output lists all branches and marks the current one with an asterisk.

bash
$ git branch
  develop
* main
  feature-x
Output
develop * main feature-x
⚠️

Common Pitfalls

Sometimes users expect git branch to show only the current branch but it lists all branches instead. Remember to look for the asterisk (*) which marks the current branch.

Another mistake is running git status in a detached HEAD state, which means you are not on any branch. In this case, the output will say HEAD detached at <commit>.

bash
Wrong:
$ git branch
  develop
  main
  feature-x

Right:
$ git branch
  develop
* main
  feature-x
📊

Quick Reference

CommandDescriptionOutput Example
git branchLists all branches, current branch marked with * develop * main feature-x
git statusShows current branch and working directory statusOn branch main Your branch is up to date with 'origin/main'.

Key Takeaways

Use git branch to see all branches and identify the current one by the asterisk (*).
Use git status to see the current branch along with file changes.
Look for the asterisk (*) in git branch output to know the active branch.
In detached HEAD state, no branch is active; git status will indicate this.
Always run these commands inside a Git repository folder.