Archive a git branch
Save this code into a bash script file & call it from any sub-directory of a git repository. This MUST be called from within your git directory or a sub-directory of it.
echo "Will Archive branch at $(git rev-parse --show-toplevel)."
echo "You must not be on the branch you're archiving."
git config --get remote.origin.url
git branch -a
read -p "Enter Branch Name: " branch;
# git checkout master
case $branch in
"" ) echo "Empty branch name. Exiting";exit;;
"q" ) echo "Empty branch name. Exiting";exit;;
"n" ) echo "Empty branch name. Exiting";exit;;
esac
git tag archive/$branch $branch
git push --tags
git branch -D $branch
git branch -d -r origin/$branch
git push origin :$branch
To use it
- Copy+paste the code into a file with no extension or a
.sh
extension wherever you like -
chmod ug+x gitarchive.sh
- The script must be executable -
cd ~/dir/to/git/repo/
-
/path/to/gitarchive.sh
& follow the prompts- See Add Bash Script To Terminal or type the full path to it when you want to use it.