Skip to content

Git Panic

Save your code in a unique place in a snap

Published by Vincent Pickering
on

Sometimes you need to quickly create a unique branch and save your code in a pinch. It could be a fire alarm, your laptop might be about to die. Any number of reasons why you may need to quickly save your code to Git and get it off your machine.

So I had the idea for a fun alias to solve this:

alias panic="branchName='$(date +%Y-%m-%d-%H-%M)' && git checkout -b panic-'${branchName}' && git add -A && git commit -m 'panic' && git push --set-upstream origin panic-'${branchName}'"

The alias just means if at any time you type git panic it will immediately create a new branch, date and time stamped, commit all your code on that branch and push it up to your Git repository.

The code is also available on a Gist.