Git - Current / working / HEAD / active branch
Table of Contents
About
The current or active branch is:
- the branch
- actually in the working tree
- 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.
Articles Related
Management
See
Local Repository
- Output the current
git branch --show-current
- The starred branch is the current branch
git branch
* branch-2.3
master
- 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
- Other command
git rev-parse --abbrev-ref HEAD
branch-2.3
Remote Repository
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
- to the remote default if it has changed
git remote set-head origin -a
# -a (or --auto) set the remote ''HEAD'' of the remote
Output:
origin/HEAD set to main