Skip to content

Instantly share code, notes, and snippets.

@sirbrillig
Created March 10, 2020 22:34
Show Gist options
  • Save sirbrillig/0e8614625154824c572ccf7fae66835e to your computer and use it in GitHub Desktop.
Save sirbrillig/0e8614625154824c572ccf7fae66835e to your computer and use it in GitHub Desktop.
Git config alias for backup and restore of current branch
[alias]
backup-create = "!f() { git branch -f backup-$(git rev-parse --abbrev-ref HEAD) && echo 'Backup created. Use git backup-restore to restore.'; }; f"
backup-restore = "!f() { echo 'Are you sure you want to overwrite the current branch with the latest backup? This cannot be undone!'; select result in Yes No; do [[ $result == "Yes" ]] && git reset --hard backup-$(git rev-parse --abbrev-ref HEAD) && echo 'Backup restored.'; break; done; }; f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment