Skip to content

Instantly share code, notes, and snippets.

@tforster
Created February 14, 2024 23:50
Show Gist options
  • Select an option

  • Save tforster/9e66ccbb8302b9e0219f0c20dfa71a29 to your computer and use it in GitHub Desktop.

Select an option

Save tforster/9e66ccbb8302b9e0219f0c20dfa71a29 to your computer and use it in GitHub Desktop.

Revisions

  1. tforster revised this gist Feb 14, 2024. 1 changed file with 31 additions and 1 deletion.
    32 changes: 31 additions & 1 deletion branch.sh
    Original file line number Diff line number Diff line change
    @@ -1 +1,31 @@
    ‎‎​
    #!/usr/bin/env bash
    #########################################################################################################################
    # branch.sh is used, with arguments, to create a new branch from main that uses a slugified ADO ticket number and title #
    #########################################################################################################################

    # Exit immediately if a command exits with a non-zero status
    set -o errexit
    # Treat unset variables as an error when substituting
    set -o nounset
    # Fails entire pipeline if any command fails
    set -euo pipefail

    # Simple function to echo out the help message.
    function help() {
    echo '
    Commands:
    branch "{number} {title}" Create a new Git branch with the ADO ticket number and title. Double quotes not required but recommended.
    api help: Display this help message
    '
    exit 0
    }

    # Help keep us branching from main
    gitBranch=$(git rev-parse --abbrev-ref HEAD)
    if [[ "$gitBranch" != "main" ]]; then
    echo "Please create feature branches from main."
    exit 1
    fi

    # Parse the arguments as input into the git branch command
    git checkout -b $(echo "$@" | iconv -t ascii//TRANSLIT | sed -r 's/[~\^]+//g' | sed -r 's/[^a-zA-Z0-9]+/-/g' | sed -r 's/^-+\|-+$//g' | sed -r 's/-$//g' | tr A-Z a-z)
  2. tforster created this gist Feb 14, 2024.
    1 change: 1 addition & 0 deletions branch.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ‎‎​