The current or active branch is:
When a index (ie next commit) is created (ie the changes are commited):
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
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
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
git remote set-head origin -a
# -a (or --auto) set the remote ''HEAD'' of the remote
Output:
origin/HEAD set to main