this post was submitted on 21 Jun 2023
7 points (100.0% liked)

Git

2910 readers
1 users here now

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Resources

Rules

  1. Follow programming.dev rules
  2. Be excellent to each other, no hostility towards users for any reason
  3. No spam of tools/companies/advertisements. It’s OK to post your own stuff part of the time, but the primary use of the community should not be self-promotion.

Git Logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.

founded 1 year ago
MODERATORS
 

My favorite is git h, which produces a nicely summarized log of commits on the current branch, with some highlighting and relative dates:

[alias]
    h = log --graph  --abbrev-commit --date=relative --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'

What's your favorite Git alias?

top 15 comments
sorted by: hot top controversial new old
[–] JackbyDev 3 points 1 year ago* (last edited 1 year ago) (1 children)

git config --global alias.git '!git' Now if you do git git status by mistake you won't get an error lol. I believe this is the most universally useful and unopinionated alias.

The ! makes it treat it as a shell command instead of a git command. Then because it is git it just basically runs the remainder as a git command lol.

[–] jnovinger 2 points 1 year ago (1 children)

Love it. I might also do igt (as in id-jit), which is what I call myself when I typo that.

[–] canpolat 3 points 1 year ago (1 children)

And gti. Apparently one cannot push a Golf GTI from command line.

[–] jnovinger 2 points 1 year ago (1 children)

Would you commit a car?!?!

[–] canpolat 3 points 1 year ago (1 children)

I don't think so. One would need to download it first.

[–] msage 2 points 1 year ago

You can't stop me!

[–] canpolat 3 points 1 year ago* (last edited 1 year ago) (2 children)

Found one on "another site":

I occasionally fat finger the git add command:

$ git dad .
git: 'dad' is not a git command. See 'git --help'.

Did you mean this?
  add

So today I fixed it:

$ git config --global alias.dad '!curl https://icanhazdadjoke.com/ && git add'

And now my clumsy typing is rewarded with comedic gold:

$ git dad .
I used to hate facial hair, but then it grew on me.

Since git's aliasing system passes any parameters on to the underlying command, your git add operation completes normally and you get a bonus dad joke.

[–] jnovinger 2 points 1 year ago

I love this and am absolutely stealing it.

[–] [email protected] 1 points 1 year ago

This is basically sl but for git.

[–] sisyphean 3 points 1 year ago

My favorites:

  • lol: log --oneline --graph --decorate
  • lola: log --oneline --graph --decorate --all
[–] canpolat 2 points 1 year ago (1 children)

The aliases I use the most are these:

st = status
co = checkout
lg = log --color --graph --date=short --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit

I see that my lg is almost identical to your h. I didn't write mine either.

I have some other aliases (mostly for log) but I rarely use them.

[–] jnovinger 1 points 1 year ago (1 children)

At this point, I don't even remember what the h stood for, my brain just knows which fingers to move to do the thing to see the history. 🤦

[–] canpolat 2 points 1 year ago (1 children)

"history" maybe? Same here, it's mostly muscle memory. When I temporarily have to work on a different PC without my aliases, I feel like everything is in slow motion :)

[–] jnovinger 1 points 1 year ago

That makes sense.

[–] jnovinger 1 points 1 year ago

Looking for a repo somewhere with a messy history to demo my git h alias and what it can show. Not having much luck.

Also, I should point out I'm not the originator of this one. I borrowed it from a former coworker years and years and years ago.