Skip to content

Instantly share code, notes, and snippets.

@stalingino
Created November 18, 2023 08:39
Show Gist options
  • Save stalingino/89bcc44d9ea3d4e8aa889cdd002cc931 to your computer and use it in GitHub Desktop.
Save stalingino/89bcc44d9ea3d4e8aa889cdd002cc931 to your computer and use it in GitHub Desktop.
git-merge & git-release for quick git flow
function git-merge {
set -x
git fetch
git checkout $1
git pull
git checkout $2
git pull
if [[ ! $(git merge $1) ]]; then
return "Merge failed for $1"
fi
if [[ ! $(git push) ]]; then
return "Push failed"
fi
}
function git-release {
set -x
if [[ ! $1 =~ ^(release-|hotfix-) ]]; then
echo "Error: Only hotfix or release branch can be released."
return 1
fi
if [[ ! $(git-merge $1 main) ]]; then
return 1
fi
if [[ ! $(git-merge main develop) ]]; then
return 1
fi
read -p "Do you want to delete the remote & local branch '$1'? (Y/N): " confirmation
if [[ $confirmation =~ ^[Yy]$ ]]; then
git push -d origin $1
git branch -d $1
else
echo "branch '$1' was not deleted."
fi
git checkout main
git tag -m "$1" $2
git push --follow-tags
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment