This gist contains a script of mine that prevents unsafe rebases.
I consider a rebase as unsafe if there is work based on the branch to rebase.
This works should work cross platform as long as bash is installed correctly on /bin/bash
(git for windows comes with bash).
This hook can be useful if git is configured to do a rebase instead of a merge when pulling.
The script (the pre-rebase
file) needs to be in the hooks
directory of the local git repository (the .git
directory) you want to work it in.
If you want the script to be added to the hooks
directory automatically, you can create a template directory for git repositories.
To do that, you just need to create a directory with a subdirectory hooks
. After that, set the init.templatedir
config to that directory (git config --global init.templatedir <your template directory>
) and copy the script (the pre-rebase
file) to the directory.