DEV Community

Stephen Chiang
Stephen Chiang

Posted on • Updated on

🔥 In case of fire: GTFO

Intro

Hopefully this will never happen to you, but even if it's not a fire or earthquake, an emergency may arise and you are pressed to get out of the office/building and you have uncommitted code.

What do you need to do❓

GTFO❗ Urban Dictionary Definition

Typically something along the lines of:

> git checkout -b emergency-exit
> git add -A
> git commit -m "Emergency exit"
> git push origin head -u
Enter fullscreen mode Exit fullscreen mode

That's a lot of commands to write with a lot of potential for misspellings and having to retype them. I wrote this for fun and thought I would share it. There's two ways I did this: a git alias, Powershell alias on top of the git alias.

Aliases

So I first create the git alias by editing the .gitconfig. I want to create an alias called tfo and create a function that calls all the git commands I listed above in succession.

So here's what that looks like (normally 1 line, but wrapped for formatting):

[alias]
    tfo = "!f() { git checkout -b emergency-exit && git add -A && git commit -m
       'Emergency exit'  && git push origin head -u; }; f"
Enter fullscreen mode Exit fullscreen mode

To call this in the terminal command line I would just type:

> git tfo
Enter fullscreen mode Exit fullscreen mode

✨ That's it! My repo now has a branch called emergency-exit and I can merge or whatever I need to do later when it's safe.

If I don't want to write git: This step is written for Powershell

Edit the .profile to alias g as git.

> New-Item alias:g -value git

// or directly in the profile.ps1 file

New-Alias g git
Enter fullscreen mode Exit fullscreen mode

To call the whole thing then, I would enter:

> g tfo
Enter fullscreen mode Exit fullscreen mode

💥 Now, I could write a global function called gtfo that does everything, or even a script, but this was fast and easy and a nice little 10 minute break.

**Important*": If you are unlucky to have to do this more than once or you did this to test it out, make sure you delete the new branch after you're done with it or you'll get an error because the branch already exists. You could probably get it to generate the branch with an incrementing number or the current date to differentiate as well.

Also if you have to do this often... Stay the F away from me...jk... But seriously... Don't come near me.

Update
Another way to make sure you don't run into a problem if the branch already exists locally is to use -B instead of -b. This creates the branch if doesn't exist and if it does, then resets it with the new changes.

If you find this valuable, please leave a comment and follow me on Dev.to @chiangs and Twitter @chiangse, 🍻 cheers!

Top comments (12)

Collapse
 
andmoredev profile image
Andres Moreno

I love the idea and it is something you can easily remember since the command relates to what you actually have to do => GTFO.
Fortunately I have never had a scenario where I really lost my work, usually it has been small things or a fire drill.

Collapse
 
somedood profile image
Basti Ortiz

This is definitely the funniest thing I've read today. 🤣

Collapse
 
qcgm1978 profile image
Youth

Why does the working command is

tfo = !git checkout -b emergency-exit && git add . && git commit -m 'Emergency exit' && git push origin head -u

and it renames my current branch? My notebook is mac.

Collapse
 
chiangs profile image
Stephen Chiang

Are you sure it renamed your branch or just switched you to the new branch? Check your list of branches.

No where in the function does it say:

> git branch -m emergency-exit

The above is what it would take to rename a branch locally.

Collapse
 
sleepyfran profile image
Fran González

Honestly if anyone finds themselves in a situation in which the branch already exists maybe they should consider switching companies instead of removing the existing branch! Great article, hope I never have to use it 😂

Collapse
 
chiangs profile image
Stephen Chiang

Haha or maybe recommend the company to change buildings!

Collapse
 
emilienmottet profile image
Emilien Mottet

Maybe

git add -A

should be more efficient than

git add .

. In case, you are not into the root of your git repo

Collapse
 
chiangs profile image
Stephen Chiang

Good idea, I'll update that, thanks!

Collapse
 
matthewpersico profile image
Matthew O. Persico

I've got that t-shirt that says something like this. I pull it on for every fire drill in my office. Maybe I need to make my own with this command instead. LOL

Collapse
 
chiangs profile image
Stephen Chiang • Edited

I'd buy that shirt... Maybe @thepracticaldev would make one!

Oh oh here's an idea... Dev should make shirts from meme-able posts and have the post url on the shirt somewhere...

Collapse
 
matthewpersico profile image
Matthew O. Persico

The shirt should have the QR code of the meme. That way instant gratification.

Collapse
 
jericomanapsal profile image
jericomanapsal

This truly is an excellent post! Although I'm constantly hoping that accidents don't happen, it does eventually. Thank you for sharing this! 🎉