Git - Current / working / HEAD / active branch


The current or active branch is:

  • The current branch is also known as the HEAD branch (in uppercase)
  • that represents the last commit known as the head (in lowercase) of the current branch

When a index (ie next commit) is created (ie the changes are commited):

  • the HEAD commit becomes the parent of the next commit (index).
  • and the committed index becomes the HEAD.



Get the current local branch name

  • The starred branch is the current branch
git branch
* branch-2.3

  • Scripting: This command prints the last name of the ref of the current HEAD which is the branch name
git rev-parse --abbrev-ref HEAD
# or 
git symbolic-ref HEAD --short
# or
git branch --show-current
  • File System: In the repository, you can see the head value of the HEAD in the HEAD file (the output shows that HEAD is a ref to the HEAD of the current branch)
cat .git/HEAD
ref: refs/heads/branch-2.3

Remote Repository / Upstream

See Git - Upstream Branch (Tracking branch).

You can see the HEAD branch with the following command

Example: below the head branch is master

git remote show origin
* remote origin
  Fetch URL:
  Push  URL:
  HEAD branch: master

The HEAD file is located at refs/remotes/<name>/HEAD

With a remote called origin, you would get the remote HEAD branch (ie default branch)

cat refs/remotes/origin/HEAD
ref: refs/remotes/origin/main

Change branch


You can change of active/current/working/HEAD branc with the checkout command


Sets or deletes the the default remote HEAD (ie local file refs/remotes/<name>/HEAD) with the command:

git remote set-head 

For instance:

git remote set-head origin main
# then push
  • to the remote default if it has changed
git remote set-head origin -a
# -a (or --auto) set the remote ''HEAD'' of the remote


origin/HEAD set to main

Discover More
Git - Clone

git clone creates a clone known as local repository from a remote repository. cloning in git means: downloading the remote repository into a newly created directory setting for each downloaded branch...
Git Commit Tree Data Model
Git - Commit

A commit in git is an object that stores the information : who saved the file system snapshots, when they were saved, why they were saved. the commiter the author the parent commit It's...
Git - Head (Head Branch | Branch Head)

The head is the last commit of a branch. while the HEAD (in uppercase) is the head of the current branch (active branch). headHEADcurrent branch page In the example below, the branch head of: ...
How to perform a text file diff in Git?

This page is text file diff in Git Diff between the head commit of the current branch (HEAD) and the current file not yet committed (in the working area) Between the head of the main branch...
Branches Git
Git - Branch

This page talks Branch management in Git. For Git, a branch is: a commit name (ref) that points to the last commit (head) leaf in the commit log (or log) that represents a commit chain Example...
What is a Git Checkout?

With a checkout, you can change the current branch (ie switch branches) or extract files/directory from branches into the working tree (file system directory) files. ie: Restore the file state from...
Git - Log (Commit History)

The commit log (log or commit hisotry) is a directed acyclique graph of commit. Example of commit log: Each leaf commit is a branch. Each time a commit is performed a node in the log graph is added....

Share this page:
Follow us:
Task Runner