hanki.dev

Git alias for creating backup branch

alias bub='current_branch=$(git rev-parse --abbrev-ref HEAD) && timestamp=$(date "+%Y.%m.%d-%H.%M") && backup_branch="${current_branch}_backup_${timestamp}" && git checkout -b "${backup_branch}" && git checkout "${current_branch}"'

^^ Above script creates a backup branch from your current branch, and names it like BRANCHNAME_backup_2023.11.22-08.43. Example output:

 ~/r/important-repo TICKET-999 > bub
Switched to a new branch 'TICKET-999_backup_2023.11.22-08.43'
M	README.md
Switched to branch 'TICKET-999'

✌🏼 Like my content? Subscribe via RSS feed.