#!/bin/bash question() { echo "`tput setaf 3`$@`tput sgr0`"; } git-update-branch(){ git checkout $1 git pull } remove-branch(){ branch=$(git branch --show-current) question "Do you really want to remove $branch? [y/n]" read -n 1 -r echo # move to a new line if [[ $REPLY =~ ^[Yy]$ ]] then git checkout develop git branch -D $branch fi } new-branch-from-develop(){ type=$1 if [ "$type" = "hotfix" ]; then git-update-branch "main"; else git-update-branch "develop"; fi question "Type the ticket code (leave it blank if there is no one):" read ticket question "What is the feature subject?" read subject subject="${subject// /-}" if [ ${#ticket} -gt 0 ]; then ticket="$ticket-"; fi git checkout -b "$type/$ticket$subject" } git-prepare(){ echo "Merging the remote develop into current branch" git fetch origin develop:develop git merge develop } git-finish(){ echo "Pushing the new branch to remote" git commit git push -u origin $(git branch --show-current) } question "What do you want to do? " items=( "Create a new feature" "Create a new hotfix" "Start a new release" "Prepare PR (merge from develop)" "Publish current branch to remote" "Create a new Pull Request" "Delete current branch from local" "Remove all untracked files" "Stash changes" "Pop stash (apply and remove)" ) select opt in "${items[@]}"; do case $opt in "Create a new feature") new-branch-from-develop "feature" break ;; "Create a new hotfix") new-branch-from-develop "hotfix" break ;; "Start a new release") new-branch-from-develop "release" break ;; "Prepare PR (merge from develop)") git-prepare break ;; "Publish current branch to remote") git-finish break ;; "Create a new Pull Request") project=$(basename `git rev-parse --show-toplevel`) xdg-open "https://bitbucket.org/furtherlearninggroup/${project}/pull-requests/new" break ;; "Delete current branch from local") remove-branch break ;; "Remove all untracked files") git clean -id break ;; "Stash changes") git stash break ;; "Pop stash (apply and remove)") git stash pop break ;; *) echo "invalid option $REPLY" ;; esac done