Is there any hook available locally in local machine, triggered whenever we switch through branch from command line?
Also how do we know which branch is we are working on by looking .git folder ?
Is there any hook available locally in local machine, triggered whenever we switch through branch from command line?
Also how do we know which branch is we are working on by looking .git folder ?
You know which branch you are working on with the git branch
command.
.git/HEAD
references the current commit (usually, the name of a branch, but it can be a tag or a commit, in case of a detached HEAD)
Since changing branch involves a checkout, you can setup a post-checkout
hook, which will be triggered each time you switch branch.
This hook is invoked when a
git checkout
is run after having updated the worktree.
The hook is given three parameters:
- the ref of the previous HEAD,
- the ref of the new HEAD (which may or may not have changed),
- and a flag indicating whether the checkout was a branch checkout (changing branches, flag=1) or a file checkout (retrieving a file from the index, flag=0).