The problem is not finding the hook (a post-checkout
hook can be used).
It is to detect that a new local branch has just been created.
But "new" compared to which branch? Detecting a "branch point" is tricky, considering you don't know which starting branch to consider.
You can also check the reflog to verify that the branch has been checked out once.
Or, you could also maintain a cache of the local branches: the output of ls .git\refs\heads
, saved somewhere as a file being said "cache".
Each time the post-checkout
hook is fired up, it would do the ls .git\refs\heads
and compare it with its cache. If a new entry is seen (and there is no similar branch in .git\refs\remotes\origin
), chances are: this is a new local branch created for the very first time.
Then the hook would update the cache file.