nb (new branch) is my very simplified method of creating new feature og fix branches in git.

When I’m working on fixes or features in an existing project, I check out a new branch. This also makes it way easier to create easily understood pull-requests when you need to get it reviewed.

# nb.zsh
nb () {
  if [[ $# > 0 ]]
    if [[ $(git branch | tr -d '* ' | grep "$1") != "" ]]
      git checkout $1
      git checkout master && git checkout -b $1
    git branch | tr -d '* '
# completion
_nb() { reply=($(git branch | tr -d '* ' | xargs echo)) }
compctl -K _nb nb

Without any arguments it just lists the current, existing, local branches. These are the ones it will tab-complete. If the argument is an existing branch then check it out, if it’s not then create it based on master.

I’m using zsh and I’m not sure what it would take to make it work in bash. Probably not too much.