Skip to content

Instantly share code, notes, and snippets.

@sgobotta
Last active April 8, 2021 19:31
Show Gist options
  • Save sgobotta/451c1491d8b4746e8b171439bc97ef33 to your computer and use it in GitHub Desktop.
Save sgobotta/451c1491d8b4746e8b171439bc97ef33 to your computer and use it in GitHub Desktop.
Checkout branches

Checkout branch util

Install

Go to the directory you want to store the script and paste the followinf code. It will download the script and create an alias in your shell init script.

  • Bash users should use .bashrc
  • Zsh users should use .zshrc
SHELL_FILE=.bashrc
wget https://gist.githubusercontent.com/sgobotta/451c1491d8b4746e8b171439bc97ef33/raw/e8edd45557d4ba7b2256d68525d18bb65ad7564f/checkout-branch.sh
echo "alias co_br="/home/sann/Documents/scripts/misc/checkout_branch.sh" >> "~/$SHELL_FILE"

Usage

It just appends two strings and replaces spaces with hyphens

# co_br <issue_number> <issue_title>
co_br 420 "As a git user I want my script installed In order to spent less time typing"
# Output
Switched to a new branch '420-As-a-git-user-I-want-my-script-installed-In-order-to-spent-less-time-typing'
#!/bin/bash
ISSUE_NUMBER=$1
ISSUE_TITLE=$2
BRANCH_NAME_SEPARATOR="-"
BRANCH_NAME=$(echo "$ISSUE_NUMBER $ISSUE_TITLE" | tr " " $BRANCH_NAME_SEPARATOR)
git checkout -b $BRANCH_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment