1

I rarely create branches off of anything but master in my daily workflow (maybe an occasionally bug fix on a release branch, etc...). With rebasing and merge squashing you can end up with a left over branch you really don't want to start a new branch from accidentally or you'll be stuck cleaning up a merge mess when you try to merge the new one into master (not realizing you didn't branch initially off of master).

I'd like a little warning when I create a new branch if the current working branch isn't master, like "Warning: Hey, you're not branching off master--think about it!"

What the best way to add this type of simple message?

Ray
  • 40,256
  • 21
  • 101
  • 138

1 Answers1

1

That looks like a pre-checkout hook. Not the actual code, but, you can do something like:

branch=$(git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/\1/p')
if [ $branch != master ]; then
    << do_you_want_to_checkout_anyway? >>
    if [ user_answered_ok ]; then exit 0
    else exit 1
    fi
fi

Save it as pre-checkout (no extension) and save it in the your project's .git/hooks

For reference: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

Mauricio Machado
  • 613
  • 1
  • 5
  • 14
  • Looks promising, but don't have that hook in version of git using currently. – Ray Oct 17 '18 at 14:33
  • No, you shouldn't, this is a new, custom one. This looks interesting for the yes/no prompt: https://stackoverflow.com/a/1885534/2502753 – Mauricio Machado Oct 17 '18 at 14:57