Created
May 3, 2023 14:19
-
-
Save siwalikm/d140d5b9ff9b098912043354abd1f7d8 to your computer and use it in GitHub Desktop.
bash script to create branches according to convention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# example branch name - TEAM-1234-FEAT-btn-revamp | |
# Select branch type | |
branch_type_options=("FEAT" "FIX" "CHORE" "HOTFIX") | |
echo "Select branch type:" | |
select branch_type in "${branch_type_options[@]}" | |
do | |
if [[ -n $branch_type ]]; then | |
break | |
fi | |
done | |
# Get branch name | |
read -p "Enter the branch name (e.g. btn-revamp): " branch_name | |
# Check if branch name has been provided | |
if [[ -z "$branch_name" ]]; then | |
echo "You must provide a valid branch name" | |
exit 1 | |
fi | |
# Get ticket number | |
read -p "Enter the ticket number (e.g. TEAM-1234): " ticket_number | |
# Check if ticket number has been provided | |
if [[ -z "$ticket_number" ]]; then | |
echo "You must provide a valid ticket number." | |
exit 1 | |
fi | |
ticket_number=$(echo "$ticket_number" | tr '[:lower:]' '[:upper:]') | |
branch_name="$ticket_number-$branch_type-$branch_name" | |
# Create branch | |
echo "Creating branch $branch_name..." | |
git checkout -b $branch_name | |
# Ask for confirmation to push branch to remote repository | |
read -r -p "Do you want to push this branch to the remote repository? [y/N] " response | |
response=$(echo $response | tr '[:upper:]' '[:lower:]') # convert response to lowercase | |
if [[ "$response" =~ ^(yes|y)$ ]]; then | |
# Push branch to remote repository | |
git push -u origin $branch_name | |
echo "Branch $branch_name has been pushed to the remote repository." | |
else | |
echo "Branch $branch_name has been created locally but not pushed to the remote repository." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment