If you start using more than the main branch, you can automatically push the current branch. My hook ( .git/hooks/post-commit ) looks like this:
#!/usr/bin/env bash branch_name=$(git symbolic-ref --short HEAD') retcode=$? non_push_suffix="_local" # Only push if branch_name was found (my be empty if in detached head state) if [ $retcode -eq 0 ] ; then #Only push if branch_name does not end with the non-push suffix if [[ $branch_name != *$non_push_suffix ]] ; then echo echo "**** Pushing current branch $branch_name to origin [i4h post-commit hook]" echo git push origin $branch_name; fi fi
It pushes the current branch if it can determine the branch name using git symbolic-ref.
β How do I get the current branch name in Git? β Deals with this and other ways of getting the current branch name.
An automatic push for each branch can be troubling when working in task branches where you expect some sort of sausage preparation to happen (you cannot easily rebase after the push). Thus, the trap will not push forward branches ending with a specific suffix (in the example "_local").
i4h Jan 20 '15 at 10:24 2015-01-20 10:24
source share