Table of Contents

Git - Current / working / HEAD / active branch

About

The current or active branch is:

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

Management

See

Get the current local branch name

git branch
* branch-2.3
  master

git rev-parse --abbrev-ref HEAD
# or 
git symbolic-ref HEAD --short
# or
git branch --show-current
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: https://github.com/ComboStrap/combo
  Push  URL: https://github.com/ComboStrap/combo
  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

Local

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

Remote

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
git remote set-head origin -a
# -a (or --auto) set the remote ''HEAD'' of the remote

Output:

origin/HEAD set to main