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 →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article