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

  1. Copy+paste the code into a file with no extension or a .sh extension wherever you like
  2. chmod ug+x gitarchive.sh - The script must be executable
  3. cd ~/dir/to/git/repo/
  4. /path/to/gitarchive.sh & follow the prompts