My aliases are either things I use regularly or things that I find useful on occasion and would otherwise have to look up every time. I've added explanatory comments to some of the less-obvious aliases.
[alias]# File changes
## gen-ignore <lang>: Outputs a .gitignore file for `lang` from gitignore.io to stdout.
gen-ignore="!_gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; _gi"## ignore/hard-ignore: See https://stackoverflow.com/a/13631525
ignore=update-index --assume-unchangedunignore=update-index --no-assume-unchangedhard-ignore=update-index --skip-worktreehard-unignore=update-index --no-skip-worktree## ls-ignored: Lists files marked with assume-unchanged.
ls-ignored=!git ls-files -v | grep '^[[:lower:]]' | cut -c 3-## ls-hard-ignored: Lists files marked with skip-worktree.
ls-hard-ignored=!git ls-files -v | grep -i '^S' | cut -c 3-word-diff=diff --word-diffchar-diff=diff --word-diff --word-diff-regex='([^[:alnum:]]|[^[:space:]])'## drop [stash_args...]: Like `reset HEAD`, but changes are recoverable from the stash reflog. Forwards arguments to `stash push`.
drop="!_drop() { git stash push \"$@\" && git stash drop; }; _drop"stat=status --short --branch# Commits
## init-commit: Initializes the repo and creates an empty initial commit.
init-commit=!git init && git commit --allow-empty -m \"Initial commit\"-m \"This commit intentionally left blank.\"amend=commit --amend --no-editfixup=commit --fixupsquash=commit --squash# Log
graph=log --graph --onelinelog-yesterday=log --since=yesterday.midnight --oneline# Branches
pulre=pull --rebase## push-new: Pushes the current branch to `origin` with the same name and sets up tracking.
push-new=push -u origin HEADpush-lease=push --force-with-lease## sq [base_branch]: Starts an interactive rebase from the base of the branch relative to `base_branch`
## (defaults to `master`; can be any ref) without applying changes on top of `base_branch`.
sq="!_sq() { git rebase --interactive --autosquash $(git merge-base HEAD ${1:-master}); }; _sq"
push-new can easily be rewritten to accept other remote names as arguments, and sq's default can be changed to use main or pull init.defaultBranch from the Git config instead of master.
I tend not to use too many short forms or have too many aliases because tab completion exists and I don't want to develop non-portable muscle memory.
French web developer mainly but touches everything. Volunteer admin mod here at DEV. I learn AI and Astro at this moment and databases. — Addict to Cappuccino and Music
# oops, missed a file in prior commit
ca = commit --amend --no-edit
fa = fetch --all --prune
# IMO this option should be the default for force pushing
pf = push --force-with-lease
# thing you do for first push of a branch
pu = push -u origin HEAD
# create a WIP commit without running precommit
wip = commit -m\"WIP\" --no-verify
# "uncommit"
pop = reset HEAD^
# list branches by most recent commit
recent = for-each-ref --sort=-committerdate --count=30 --format='%(refname:short)' refs/heads/
Did you know you can shorten your gmd alias to just git pull origin development (assuming origin is the correct remote)? It's not exactly the same since it won't update your local development branch, but it will do the important part and make your current branch up to date with the remote development.
The only one I sometimes configure is git s for status, but even that I usually just type out. One thing I did alias was merging current branch to our integration branch, which lets me easily chain either the push or the push and checkout $currb after it, or waiting for the CI pipeline to start before pushing.
Though I do sometimes think about aliasing m to merge --no-edit and ca to merge --amend --no-edit, because I often forget to add the no-edit param and get annoyed by the need to quit nano.
The thing that confuses is that alias set is very uneven in sense of pressings. If you press something on keyboard, you anyway press some sequences, and all git commands start with "git " - already 4 presses... After it, difference, for example, between "git br" = "git branch -r" and "git b -r" where "b" is already aliased as "branch" is nearly void, compared with any other difference. This suggests the alias set is accrued historically without substantial reconcerning.
Alias "db" is dangerous. I prefer to write such actions only explicitly. Same for "op": it's normal to refer to something done a few days ago, and for "vc". (BTW do you use IDE? Something like "git clean -dfx -e .vscode" would be better.)
What is use case for "search"?
"last" could be extended with "--stat" to show changes, because anyway only a single commit is printed.
OTOH, it clearly exposes some manners and developing approaches - as presence of "main" and "devel" branches. For me, it showed some features I was unaware or forgot them due to standing out of usual habits... thanks for this.
Formatting was broken - e.g. what is "git alias" is unparseable (seems the website markdown was active). If it allows editing the post, please reconsider.
To compare, my typical set (with comments):
ae = add -e
Maybe more specific to my manner, but it is typical to cache only some changes among ones in file (others could be for later commits, not committed as debug, etc.) - just interactive mode is not enough. Git's recalculating of chunk line count works well enough.
amsh = am --show-current-patch
In rebase, sometimes it is needed to see full patch to apply now.
b = branch
Just shortening for all branch related commands.
cbr = rev-parse --abbrev-ref HEAD
"current branch" in an easy solitary way.
cia = commit --amend
ciah = commit --amend -C HEAD
To adjust the last commit with catch-up changes.
ci = commit
co = checkout
Habitual from previous VCSes. To edit commit message is more useful because it never should be one-liner in a final version.
dc = diff --cached
Obviously needed before commit is created from parts.
Rare but... for a new work, having basic empty commit is crucial to keep the first commit clear. Otherwise, complex dances with filtering are needed. (I'm wondering why it is not in Git base logic.)
I'd also note some crucial settings out of aliases:
merge.conflictstyle=diff3
To show base version for a conflict - crucial both for a human and automatic merging tools.
pager.status=true
Otherwise some tools avoid paging.
push.default=simple
Never push many-to-many without an explicit specification in a command.
pull.ff=only
Useful default to minimize underwater pull effects.
I name it git-new-pr, and add it to my $PATH. Then, I can call git new-pr, and it'll automatically open up a page for a new PR in my browser.
This script is for macOS. So, the last line opens the URL in the default browser. If using Linux, this could be xdg-open $PR_URL. Also, a specific browser could be specified.
Most people would just use the GitHub cli for this, but I've never bothered installing it, and this works really well.
alias gco="git checkout"
alias gpsp="git push -o ci.skip"
alias gswc="git switch -c"
alias gmwps="git push -o merge_request.create -o merge_request.target=master -o merge_request.merge_when_pipeline_succeeds"
alias gdfw="git diff --word-diff"
alias gmrt="git merge --strategy recursive -X theirs"
alias gbr="git branch --remotes --verbose --sort=-committerdate"
alias gbl="git branch --verbose --sort=-committerdate"
alias gps="git push"
alias gpl="git pull --rebase"
alias gpom="git push origin master"
alias gpomn="git push origin main"
alias gf="git fetch"
And some specific commit messages (conventional commit is a thing):
alias gcsmb='f() { git commit -S -m "[BUILD]: $1" };f'
alias gcsmc='f() { git commit -S -m "[CHORE]: $1" };f'
alias gcsmf='f() { git commit -S -m "[FEAT]: $1" };f'
alias gcsmfx='f() { git commit -S -m "[FIX]: $1" };f'
alias gcsmd='f() { git commit -S -m "[DOCS]: $1" };f'
alias gcsmt='f() { git commit -S -m "[TESTS]: $1" };f'
I didn't read all that were postet but here are mine that I love the most.
alias editaliases='vi ~/.zsh_aliases'
alias loadaliases='source ~/.zsh_aliases'
alias gb='git branch'
alias gs='git status'
alias ga='git add'
alias gclean='git clean -f -d'
alias gcomm='git commit -m'
alias gmerge='git merge --no-ff -e'
alias gpush='git push'
alias pfusch='git push -f'
alias grsh='git reset HEAD --hard'
alias gback='git switch -'
alias glog="git --no-pager log $1 --pretty=format:'%Cgreen%h%Creset - %<(75,trunc)%s %C(bold blue)%<(15,trunc)<%an>%Creset %Cgreen%cr%Creset %C(yellow)%d%Creset' --abbrev-commit --date=relative"
alias glogl="glog -10"
alias glogy="glog --since=yesterday.midnight"
alias glogt="git log --graph --pretty=format:'%Cgreen%h%Creset - %s %C(bold blue)<%an>%Creset %Cgreen%cr%Creset %C(yellow)%d%Creset' --abbrev-commit --date=relative"
alias glogtl='glogt -10'
alias glogf="git log --pretty=format:'%Cgreen%h%Creset - %<(75,trunc)%s %C(bold blue)%<(15,trunc)<%an>%Creset %Cgreen%cr%Creset %C(yellow)%d%Creset' --abbrev-commit --date=relative --follow"
alias gfiles='git diff-tree --no-commit-id --name-only -r'
alias gitrect="git reset HEAD --hard"
Most used by me is glogl (git log last) and glog -100 (git log last 100)
Wow, I think @tpenguinltg probably has some of the most elaborate ones I've seen, nice config you have there!
And all of you have shared practical examples; hats off to the author and others who shared their aliases. I will add mine here, though most of them are a bit generic and unimaginative. 😅
I do not take credit for these all myself, many I have adopted and modified along the way to fit my needs, and I hope you all can find something useful. Cheers!
Well, my git alias list is not that long. It's like 8 lines which are for the most used git commands. And I don't have aliases for commands with different flags.
But that's the good thing about it, personalization rules.
I don't believe using aliases is a good idea. I seldom use it even in my shell, but I prefer to leave it out entirely with applications that I might not be the only one using. And Git is definitely not something of which I'm the sole user, so avoiding aliases makes it much easier to remember the full commands as they would be available for my friends and colleagues if I need to help them out, or if I'll be writing documentation on how we're doing certain processes.
In those cases I think using an alias will cause more harm than good, and so I avoid them. The extra keystrokes are not an issue for me, as I'm a slow thinker anyways, haha.
NB "git wip" conflicts with standard alias setting for Gerrit, for which injection of an alias series "ready", "wip", etc. is suggested (and supported by a local installer).
My aliases are either things I use regularly or things that I find useful on occasion and would otherwise have to look up every time. I've added explanatory comments to some of the less-obvious aliases.
push-newcan easily be rewritten to accept other remote names as arguments, andsq's default can be changed to usemainor pullinit.defaultBranchfrom the Git config instead ofmaster.I tend not to use too many short forms or have too many aliases because tab completion exists and I don't want to develop non-portable muscle memory.
Wow! I will take some from you and adding to my list of learning commands. Thanks!
Good timing this post!
I recreated my WSL space on my Windows 10, and I created some aliases for git and others commands.
😄🙌
Good ones @thomasbnt Thank you!!!
Great list! Will definitely add a few of these.
A few more that I like:
Thanks for sharing @ehaynes99 ! I will take note of yours too.
wow… @tpenguinltg ’s stuff - that’s on a different level entirely (: can’t wait to try some of those!
i use many of the aliases shared by others regularly. one alias in particular saves me a ton of time daily:
development/master/etcdevelopment), then lastlyIt’s not strictly a git alias, i know, though you could prob make that work 🤷♂️ never tried 😉 useful nonetheless IMH
I use it anytime i’m done with a feature and need push and open a PR on main.
great post. inspiring stuff!
Did you know you can shorten your
gmdalias to justgit pull origin development(assumingoriginis the correct remote)? It's not exactly the same since it won't update your localdevelopmentbranch, but it will do the important part and make your current branch up to date with the remotedevelopment.The only one I sometimes configure is
git sfor status, but even that I usually just type out. One thing I did alias was merging current branch to our integration branch, which lets me easily chain either the push or the push and checkout $currb after it, or waiting for the CI pipeline to start before pushing.Though I do sometimes think about aliasing
mtomerge --no-editandcatomerge --amend --no-edit, because I often forget to add the no-edit param and get annoyed by the need to quit nano.Thanks for your comments @fjones
The thing that confuses is that alias set is very uneven in sense of pressings. If you press something on keyboard, you anyway press some sequences, and all git commands start with "git " - already 4 presses... After it, difference, for example, between "git br" = "git branch -r" and "git b -r" where "b" is already aliased as "branch" is nearly void, compared with any other difference. This suggests the alias set is accrued historically without substantial reconcerning.
Alias "db" is dangerous. I prefer to write such actions only explicitly. Same for "op": it's normal to refer to something done a few days ago, and for "vc". (BTW do you use IDE? Something like "git clean -dfx -e .vscode" would be better.)
What is use case for "search"?
"last" could be extended with "--stat" to show changes, because anyway only a single commit is printed.
OTOH, it clearly exposes some manners and developing approaches - as presence of "main" and "devel" branches. For me, it showed some features I was unaware or forgot them due to standing out of usual habits... thanks for this.
Formatting was broken - e.g. what is "git alias" is unparseable (seems the website markdown was active). If it allows editing the post, please reconsider.
To compare, my typical set (with comments):
Maybe more specific to my manner, but it is typical to cache only some changes among ones in file (others could be for later commits, not committed as debug, etc.) - just interactive mode is not enough. Git's recalculating of chunk line count works well enough.
In rebase, sometimes it is needed to see full patch to apply now.
Just shortening for all branch related commands.
"current branch" in an easy solitary way.
To adjust the last commit with catch-up changes.
Habitual from previous VCSes. To edit commit message is more useful because it never should be one-liner in a final version.
Obviously needed before commit is created from parts.
Maybe "cp -n", etc. is enough but often used in some flows.
Convenience for log view styles.
For some flows, merge is impossible - it's required to actualize the working state regularly.
Interactive rebase helpers in different styles to keep propositions clear.
Rare but... for a new work, having basic empty commit is crucial to keep the first commit clear. Otherwise, complex dances with filtering are needed. (I'm wondering why it is not in Git base logic.)
I'd also note some crucial settings out of aliases:
To show base version for a conflict - crucial both for a human and automatic merging tools.
Otherwise some tools avoid paging.
Never push many-to-many without an explicit specification in a command.
Useful default to minimize underwater pull effects.
Thanks @netch80 I have reviewed the post and I some backslashes were missing. Thanks for your comments. Really helpful.
Nice, thanks for sharing.
I would add some of my aliases
Thanks for sharing you too!!
Also, for work specifically, my company works on GitHub, and I have a bash script to easily create a new PR from the current branch.
I name it
git-new-pr, and add it to my$PATH. Then, I can callgit new-pr, and it'll automatically open up a page for a new PR in my browser.This script is for macOS. So, the last line opens the URL in the default browser. If using Linux, this could be
xdg-open $PR_URL. Also, a specific browser could be specified.Most people would just use the GitHub cli for this, but I've never bothered installing it, and this works really well.
Thanks for sharing @goodevilgenius !!
Great aliases you've got!
I have just one git alias at the moment and that is:
This comes very handy especially if you contribute to open source projects frequently.
Thanks @thisisobate ! Added to my list
general ones:
And some specific commit messages (conventional commit is a thing):
Thanks for sharing @vikmstr !!!
using zsh
I mostly just stick with these:
alias gdiff="git difftool"
alias gap="git add -p"
Everything else is longform because I prefer to be familiar with the most common commands in case i'm ever not on a computer that's mine.
Thanks @tw2113 I will add them to my list.
I didn't read all that were postet but here are mine that I love the most.
Most used by me is glogl (git log last) and glog -100 (git log last 100)
It creates an output like:
Thanks @loebkes for sharing. Really cool one.
Wow, I think @tpenguinltg probably has some of the most elaborate ones I've seen, nice config you have there!
And all of you have shared practical examples; hats off to the author and others who shared their aliases. I will add mine here, though most of them are a bit generic and unimaginative. 😅
Thanks for sharing @killshot13 !!
Well, my git alias list is not that long. It's like 8 lines which are for the most used git commands. And I don't have aliases for commands with different flags.
But that's the good thing about it, personalization rules.
I have only two aliases:
Haha! Love the second one. Thanks for sharing @primo
I don't believe using aliases is a good idea. I seldom use it even in my shell, but I prefer to leave it out entirely with applications that I might not be the only one using. And Git is definitely not something of which I'm the sole user, so avoiding aliases makes it much easier to remember the full commands as they would be available for my friends and colleagues if I need to help them out, or if I'll be writing documentation on how we're doing certain processes.
In those cases I think using an alias will cause more harm than good, and so I avoid them. The extra keystrokes are not an issue for me, as I'm a slow thinker anyways, haha.
I understand @necrophcodr , You can always have them to learn new commands and git options. Thanks for sharing!
I dont use any :))
xD
dev.to/austincunningham/git-log-pr...
Nice one @austincunningham Thanks!
I have a handful of useful git aliases that help me be more productive:
Thanks for sharing @michi
NB "git wip" conflicts with standard alias setting for Gerrit, for which injection of an alias series "ready", "wip", etc. is suggested (and supported by a local installer).
Wow! didn't know that. Thanks @natescode !!
I really only do two
git fixup
And
My first git alias
Jamund Ferguson ・ Apr 16 '21 ・ 2 min read
Thank you @jessekphillips
Really like this discussion. Added many of these to my .gitconfig
Thanks @hasii2011
Hello, how do I add my alias
Hi @motuncoded , just create a
.gitaliasfile in your home:cat ~/.gitconfig, and add your list in the[alias]section as shown in the post.Let me know if it help.
Thank you!
Nice ones also @ginomempin . Thanks for sharing!
Sorry to be a Party Pooper!!
But why not use ZSH with the Oh ZSH add-on and it's various plugins. ohmyz.sh/
Even posted on Dev.to
dev.to/0xkoji/do-you-know-oh-my-zs...