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.
Management
See
Get the current local branch name
- The starred branch is the current branch
git branch
* branch-2.3
master
- 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: 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