Last active
June 29, 2016 17:10
-
-
Save thaicloud/cf1be6efd0a7ae4d6913be6c9375d0be to your computer and use it in GitHub Desktop.
Bash archive-branch
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
# Check out a Git branch, tag it with archive/, remove | |
# the remote branch, and get ready to do it all over again. | |
# | |
# USAGE: | |
# archive-branch feature/my-branch | |
function archive-branch() { | |
if [[ "$1" == "master" ]]; then | |
echo "I'm sorry, $USER. I'm afraid I can't do that. (Cannot archive master branch)" | |
return | |
fi | |
if [ "git branch --list $1" ] | |
then | |
git branch -D "$1" | |
fi | |
git fetch origin "$1" && echo "fetched feature: $1" \ | |
&& git checkout -b "$1" --track origin/"$1" \ | |
&& git tag archive/"$1" && echo "Tag created: archive/$1" \ | |
&& git push origin archive/"$1" && echo "Pushed to origin: archive/$1" \ | |
&& git push origin :"$1" && echo "Removed remote branch $1" \ | |
&& git checkout master && git branch -d "$1" | |
echo "" | |
} | |
# Run through archive-branch in a loop, useful for archiving a *bunch* of | |
# merged branches in a repo. | |
# | |
# USAGE: | |
# archive-branches fix/my-fix feature/some-feature | |
function archive-branches() { | |
echo "Archiving Git branches:" | |
echo "" | |
for branch in "$@"; do | |
echo "Running archive-branch $branch:" | |
archive-branch "$branch" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment