DEV Community

Clinton N. Dreisbach
Clinton N. Dreisbach

Posted on

4 2

Make git friendlier with aliases

Git drives me crazy with its obtuse command-line interface. Over time, I’ve added many aliases to my ~/.gitconfig in order to make its interface more clear.

Here are some of my favorites:

aliases = config --get-regexp ^alias\\.
discard = checkout --
generate-ignore = "!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi"
list-tracked = ls-tree -r HEAD --name-only
list-ignored = ls-files --others -i --exclude-standard
new-branch = checkout -b
push-branch = "!git push -u origin `git rev-parse --abbrev-ref HEAD`"
uncommit = reset --mixed HEAD~
unstage = reset -q HEAD --

aliases lists all my aliases. It could be formatted a bit better, but works well for me.

discard lets me discard changes to a file I'm working on. I never remember how to do this, especially as it uses the same command you use to switch branches.

generate-ignore can generate a .gitignore file for me. I use this at the start of each project.

new-branch and push-branch are huge for me. new-branch makes it explicit that I’m trying to create a new one, and push-branch pushes my local branch to a (generally new) branch of the same name on my origin repo.

uncommit and unstage are quick ways to reverse a mistake I’ve made without having to search for those arcane commands.

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (1)

Collapse
 
vonheikemen profile image
Heiker

This is awesome. I think people don't do this enough. A lot of people try to "optimize" for keystrokes and end up with weird stuff like gcstp. These type of alias feel better.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay