Last active
May 6, 2021 12:52
-
-
Save Dragod/1b076417abdfe444ea2f56034c14ace1 to your computer and use it in GitHub Desktop.
Create and delete feature branch from dev
This file contains 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
# Create new feature branch from sd-unity-4-0 dev branch | |
# Red | |
RED='\033[0;31m' | |
# Color Function | |
alert(){ | |
echo -ne $RED$1$clear | |
} | |
function createBranchFromDev() | |
{ | |
if [ "$1" ]; then | |
printf "\n\rCreating feature core branch: sd-feature-core-$1-1 from \"dev\" branch\n\r" | |
eval "git checkout dev" | |
eval "git pull" | |
eval "git checkout -b sd-feature-core-$1-1 dev" | |
eval "git push --set-upstream origin sd-feature-core-$1-1" | |
printf "\n\rSuccess! Created feature core branch: sd-feature-core-$1-1 from \"dev\" branch\n\r" | |
else | |
echo "Error in creating the feature branch please try again..." | |
fi | |
} | |
alias feature=createBranchFromDev | |
# Delete a feature branch from sd-unity-4-0 | |
# It does ask for confirmation before permanent deletion | |
function deleteFeature(){ | |
if [ "$1" ]; then | |
# Ask for branch deletion confirmation | |
echo #space | |
echo -ne $(alert "- Are you sure you want to PERMANENTLY DELETE the feature core branch: \"sd-feature-core-$1-1\" ? (y,yes or n,no): ") | |
read yesorno | |
if [ "$yesorno" = yes ] || [ "$yesorno" = y ] ; then | |
echo #space | |
# Can't delete a branch while you are actively on it, so need to switch on dev | |
eval "git checkout dev" | |
# Delete branch locally | |
eval "git branch -d sd-feature-core-$1-1" | |
# Delete branch from remote | |
eval "git push --delete origin sd-feature-core-$1-1" | |
# Need git fetch to update branch deletion | |
eval "git fetch -p" | |
# Try to checkout deleted branch, should return a pathspec error if branch was deleted | |
printf "\n\r If git return a pathspec error below, it means the feature branch as been deleted correctly.\n\r" | |
eval "git checkout sd-feature-core-$1-1" | |
elif [ "$yesorno" = no ] || [ "$yesorno" = n ] ; then | |
printf "\n\rFeature core branch: \"sd-feature-core-$1-1\" was NOT DELETED\n\r" | |
printf "\n\rScript will now exit...\n\r" | |
else | |
printf "\n\rNo vailid answer, script will now exit...\n\r" | |
fi | |
else | |
printf "\n\rYou need to pass a feature branch number.\n\r" | |
printf "\n\rEx: \"deleteFeature 55432\" witch will be converted to \"sd-feature-core-55432-1\"\n\r" | |
printf "\n\rScript will now exit...\n\r" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment