Skip to content

Instantly share code, notes, and snippets.

@dannylagrouw
Created June 12, 2019 08:39
Show Gist options
  • Save dannylagrouw/2cdaf21fd5bd94d7128e6cf33c41ba9b to your computer and use it in GitHub Desktop.
Save dannylagrouw/2cdaf21fd5bd94d7128e6cf33c41ba9b to your computer and use it in GitHub Desktop.
Lets user select a git branch to archive.
#!/usr/bin/env bash
echo "--------------------------------------------------------------------------------"
echo "Select a branch to archive"
echo "--------------------------------------------------------------------------------"
PS3="Branch no or 0 to quit> "
options=( $(git branch -l | grep --invert-match '*' | grep --invert-match 'master') )
select opt in "${options[@]}"; do
if [[ $opt != '' ]]; then
echo "Archiving $opt ..."
git tag archive/$opt $opt
git branch -D $opt
echo "Done. To restore, type:"
echo "git checkout -b $opt archive/$opt"
fi
break
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment