Created
November 10, 2020 07:00
-
-
Save ATahhan/a98029c69dfa5cea9f3a4c146e1774db to your computer and use it in GitHub Desktop.
Script to create a new feature and sub-feature branches
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
# Paste inside '.bash_aliases' file in your root directory | |
# Parameters: | |
# $1 = New feature branch name (without 'feat/' prefix) | |
# $2 = Base branch to start the feature branch from (optional) | |
function feature_branch() { | |
current_branch="" | |
if [ -z "$2" ] | |
then | |
current_branch=$(git symbolic-ref --short -q HEAD) | |
echo "New feature branch will be named: ${"feat/$1"}" | |
echo "Starting branch name not found. Would you like to start from the current branch [${current_branch}]?" | |
echo "Press anything to continue, or 'q' to exit" | |
while : ; do | |
read -n 1 k <&1 | |
if [[ $k = q ]] ; then | |
return | |
else | |
break | |
fi | |
done | |
else | |
git checkout $2 | |
current_branch=$(git symbolic-ref --short -q HEAD) | |
fi | |
echo "Continuing from ${current_branch}" | |
git checkout -b "feat/$1" | |
if [ $? != 0 ]; then | |
echo "Couldn't checkout new branch: " + "feat/$1" | |
return | |
fi | |
# Make sure nothing is staged before committing empty [ci skip] | |
git reset HEAD | |
# Committing [ci skip] not to trigger a build on Bitrise, can be removed if Bitrise is not used | |
git commit --allow-empty -m "[ci skip]" | |
# Pushing new base feature branch to 'origin' remote | |
git push origin -u | |
# Starting a new sub-feature branch | |
git checkout -b "$1/impl" | |
# Setting up cocoapods, you can any other steup you want or open the project directly | |
pod install | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment