News

The Ultimate "git nah" Alias

Published
The Ultimate "git nah" Alias image

Recently, developer Liam Hammett shared a fabulous git nah snippet on Twitter that is better than your existing git nah alias 🔥

I know lots of people use a "nah" alias to abort their current changes, but they usually limit it to "git reset --hard".

I like to do more by cleaning and aborting any potential rebase. If I use the "nah" command, I know I want a fresh start, so this helps

He shared two versions, including setting it up as a git alias:

# Git alias ⬇️
[alias]
nah = "!f(){ git reset --hard; git clean -df; if [ -d ".git/rebase-apply" ] || [ -d ".git/rebase-merge" ]; then git rebase --abort; fi; }; f"

If you prefer a bash function instead, here's that version that you would add to your .bashrc or .zshrch file:

# Bash function ⬇️
nah () {
git reset --hard
git clean -df
if [ -d ".git/rebase-apply" ] || [ -d ".git/rebase-merge" ]; then
git rebase --abort
fi
}

Depending on which snippet you prefer, here's how you'd run it:

# Alias
$ git nah
 
# Bash
$ nah

What are some of your favorite git aliases? Share them with us!

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Major performance improvements & security patches for Filament v4.12 and v5.7! image

Major performance improvements & security patches for Filament v4.12 and v5.7!

Read article
Laravel Boost Project Rules: Teach Agents Your Conventions image

Laravel Boost Project Rules: Teach Agents Your Conventions

Read article
Extract an Image's Dominant Color in Laravel image

Extract an Image's Dominant Color in Laravel

Read article
Image Dominant Color and HEIC Support in Laravel 13.24 image

Image Dominant Color and HEIC Support in Laravel 13.24

Read article
Official Laravel Zed Extension: LSP for PHP & Blade image

Official Laravel Zed Extension: LSP for PHP & Blade

Read article
Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD image

Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD

Read article