To check the Git branch for a Terminal window on your Mac, run git branch --show-current in that window. Git prints the branch checked out for the repository at the shell’s current location. If it prints nothing, the checkout may be in detached HEAD state; if Git reports that it is not a repository, check the window’s directory first.
Check the branch in the current Terminal window
Click the Terminal window you want to identify, then enter this command and press Return:
git branch --show-current
For example, output such as feature/search means this shell is in a Git working tree with that branch checked out. This command reports the current branch name without listing every branch. Git’s documentation says it prints nothing in detached HEAD state, when the checkout points directly to a commit rather than a named branch. Git’s git branch documentation
The answer applies to the directory from which the command runs. Each Terminal window or tab can have a different current directory, so run the command in the specific window you mean to check. If you have several similar windows, confirm the project directory as well as the branch before acting.
Confirm which project the window is in
Run pwd to print the shell’s current directory. Then use Git to identify the working tree’s top-level directory:
pwd
git rev-parse --show-toplevel
The first command shows the current location; the second prints the repository root when the current directory belongs to a working tree. Git documents that --show-toplevel reports an error if there is no working tree. Git’s git rev-parse documentation
This extra check helps when two projects use similar branch names, or when the shell is inside a nested folder. In a subdirectory of a repository, Git still identifies the enclosing working tree and its checked-out branch. The path is useful evidence of which project you are viewing; the branch command alone does not identify the project by name.
Use git status as a second check
For a quick combined check, run:
git status -sb
The short status format with -b includes a branch line and a compact summary of file changes. For example, ## main identifies the branch as main; additional text may describe tracking status. git status also helps you notice modified, staged, or untracked files before you continue. Git documents that -b shows branch and tracking information in short format. Git’s git status documentation
Branch identification and file status answer different questions. The branch name tells you which named branch is checked out; the remaining status output tells you whether the working tree has changes. A clean status does not mean a branch is current with a remote, and the branch name alone does not reveal whether files have been edited.
If the command does not show a branch
If Git says the current directory is not a repository, the shell may be in your home folder, another project, or a directory outside the working tree. Use pwd to see where you are. If you know the project’s location, change to that directory with cd and run the branch command again. For example, replace the sample path with your actual project path:
cd ~/Projects/sample-project
git branch --show-current
If you are already in a repository but the branch command returns no text, check git status -sb. Git’s documented behavior for --show-current is to print nothing in detached HEAD state. The status output can show (HEAD detached at ...); in that state, there is no current local branch name to report. Avoid treating the last branch you remember using as the current one.
Make the project easier to recognize in Terminal
macOS Terminal can show a working directory in a window or tab title. To configure it, open Terminal > Settings, choose Profiles, select the profile used by the window, and click Window to select title information such as the working directory or its path. Tab titles have their own settings under Profiles > Tab. Apple notes that profile settings apply to the selected profile, so check the profile in use if a title does not change. Apple’s Terminal guide to window titles and Apple’s Terminal guide to tab titles
A directory title helps distinguish project locations, but it does not display Git’s branch by itself. For a definitive branch check, run git branch --show-current in the relevant window; use git status -sb if you also want a compact view of changes and tracking information.