Introduction
I've been requested multiple times about sharing my .gitconfig
to copy my aliases.
I use git aliases for two reasons:
- To improve productivity.
- To remember interesting
git
commands and learn from them.
My Gitconfig
These are my aliases included in my ~/.gitconfig
file for your reference:
[alias]
a = add .
aliases = config --get-regexp alias
alias = ! git config --get-regexp ^alias\\. | sed -e s/^alias.// -e s/\\ /\\ $(printf \"\\043\")--\\>\\ / | column -t -s $(printf \"\\043\") | sort -k 1
ap = add . -p
addups = remote add upstream
bd = branch -d
bi = bisect
bl = branch -l
blr = branch -a
br = branch -r
ca = commit -a
cam = commit -a -m
ci = commit -m
cia = commit --author='imjoseangel <anotheremail@example.com>' -m
cm = commit
co = checkout
colast = checkout -
comments = commit -m 📒Comments
count = rev-list --count devel
db = branch -D
forgetAbout = rm --cached
formatting = commit -m 💅Formatting
fp = fetch -p
grep = grep -F
laf = fsck --lost-found
last = log -1 HEAD
latest = log -5 --pretty --oneline
ls = ls-files --others --exclude-standard -z
mend = commit --amend
nb = checkout -b
op = gc --prune=now --aggressive
pdo = push -d origin
pf = push --force-with-lease
po = push origin
pou = push --set-upstream origin
pr = pull --rebase
pror = remote prune origin
prud = pull --rebase upstream devel
prum = pull --rebase upstream main
prune = remote update --prune
ptag = push origin --tags
ra = rebase --abort
rc = rebase --continue
refactor = commit -m 👷Refactor
remotes = remote -v
renb = branch -m
rh = reset --hard
rhh = reset --hard HEAD
ri = rebase -i upstream/devel
rim = rebase -i upstream/main
rl = reflog
rp = repack -ad
s = status -s
search = rev-list --all
sh = show
short = shortlog -sn
sign = commit --amend --no-edit --signoff
st = status
stashes = stash list
tests = commit --allow empty -m ✅Tests
tuto = help tutorial
tuto2 = help tutorial-2
unstash = stash pop
vc = clean -dfx
wow = log --all --graph --decorate --oneline --simplify-by-decoration
Running git alias
after adding to the .gitconfig
shows the list of all the aliases as a reference list.
To get more info, just run git help <command or alias>
. For instance:
git help st
'st' is aliased to 'status'
git help status
There are two aliases I find interesting for beginners:
git tuto
git tuto2
Comments and suggestions with different approaches are always welcomed.
Top comments (48)
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-new
can easily be rewritten to accept other remote names as arguments, andsq
's default can be changed to usemain
or pullinit.defaultBranch
from 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
gmd
alias to justgit pull origin development
(assumingorigin
is the correct remote)? It's not exactly the same since it won't update your localdevelopment
branch, but it will do the important part and make your current branch up to date with the remotedevelopment
.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.
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
tomerge --no-edit
andca
tomerge --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
Nice, thanks for sharing.
I would add some of my aliases
Thanks for sharing you too!!
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
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 !!