Wrist-friendly Git Shortcuts and Aliases #️⃣#
Things tend to get repetitive with git after you start consistently using it. Of course, it’s still an irreplaceable tool, but that doesn’t mean we cannot try to abide by DVORAK principles and minimize the distance our fingers travel on the keyboard.
As past and current colleagues can attest, I’m a serial keyboard customizer and shortcut afficionado, so my suggestion to give git console aliases a try should not come as a surprise.
Stay in touch by entering your email below and receive updates whenever I post something new:
As always, thank you for reading and remember that feedback is welcome and appreciated; you may contact me via email or social media. Let me know if there's anything else you'd like to know, something you'd like to have corrected, translated, added or clarified further.
Addendum#
Once you’re done reading this article, you can continue by having a look at the related content I’ve linked below.
Background#
My list of BASH aliases has grown over the years, but I do use some more often than others in case you’re wondering. Feel free to cherry pick those that suit you best.
📦 An auto-generated aliases file based on this blog post is available on GitHub and also on GitLab in case you prefer bookmarks. The same file can be downloaded directly here.
To use them simply include them in your ~/.bash_aliases
file and source it by running source ~/.bash_aliases
or open a new terminal. Alternatively, you can apply a similar concept and use git aliases instead.
Note
Be careful while editing ~/.bash_aliases
, especially when mixing aliases for different commands. My approach has always been to have different sections with a comment delimiter such as ######### git aliases ########
. Similarly, remember some of your new aliases might be already associated with other commands, for example gs
in the case of ghostscript
.
Basic#
1alias g='git'
2
3alias gg='git clone'
4alias ggg='git clone --recursive' # clone repository and submodules
5
6alias gs='git status -s' # short status
7alias gss='git status'
8alias gsr='git show' # show revision
9
10alias gd='git diff'
11alias gds='git diff --staged' # diff against the staged changes in the index
12alias gdw='git diff --word-diff'
13
14alias ga='git add'
15
16alias gb='git branch'
17alias gba='git branch -a' # show all branches
18alias gbd='git branch -d' # delete a branch
19alias gcb='git checkout -b' # create a new branch
20
21alias gco='git checkout' # git checkout
22alias gcm='git checkout main' # checkout the main branch
23alias gch='git checkout HEAD --' # checkout following files from the HEAD in the current branch
24
25alias gc='git commit -m' # commit with message following
26alias gce='git commit --allow-empty-message -m "" ' # commit with empty message
27
28alias gm='git merge'
29
30alias gfa='git fetch --all --prune' # fetch all remote branches and remove local, non-existent ones
31
32alias gl='git pull'
33
34alias gp='git push'
35
36alias grba='git rebase --abort'
37alias grbc='git rebase --continue'
38alias grbs='git rebase --skip'
39alias grbi='git rebase -i' # interactive rebase
git commit
#
1alias gca='git commit -a -m' # commit all changed files, without adding first
2
3alias gcv='git commit -v' # include diff in commit message template
4
5alias gcs='git commit -s' # include status in commit message template
6
7alias gcs='git commit -S' # GPG sign commit
git add
#
1alias gat='git add -u' # add files which are tracked already
2
3alias gaa='git add --all' # add all files, modified and untracked
4
5alias gapa='git add --patch' # interactively select changes to be added
git add++
#
1# add tracked files, generate a commit message, commit with said message and push
2alias gf='status=`git -c color.status=false status`;\
3 message=`echo "$status"|\
4 sed -n -r\
5 -e "1,/Changes to be committed:/ d"\
6 -e "1,1 d" -e "/^Untracked files:/,$ d"\
7 -e "s/^\s*//"\
8 -e "/^.*git restore/ d"\
9 -e "/./p"`;\
10 echo $message;\
11 git commit -m "message";
12 sleep 0.1;
13 git push'
Cleaning#
1alias grh='git reset HEAD' # equivalent to --soft, reset only HEAD
2
3alias grhh='git reset HEAD --hard' # reset HEAD, index AND working tree with HEAD
4
5alias gclean='git clean -f -d -i' # interactively and forcefully remove files and directories which are not under version control
6
7alias gpristine='git reset --hard && git clean -d -f -x' # leave the HEAD, index and working tree in an equivalent state to HEAD
git remote
#
1alias grs='git remote -v'
2
3alias grmv='git remote rename'
4
5alias grrm='git remote remove'
6
7alias grset='git remote set-url'
Git Graphical User Interfaces#
1alias gkb='gitk --all&'
2
3alias gk='gitx --all'
4
5alias gmt='git mergetool --no-prompt'
git stash
#
1alias gsta='git stash save'
2
3alias gstaa='git stash apply'
4
5alias gstl='git stash list'
6
7alias gsts='git stash show --text'
8
9alias gstd='git stash drop'
10
11alias gstp='git stash pop'
git log
#
1alias glogt='git log --graph --max-count = 10'
2
3alias gloga='git log --graph --decorate --all'
4
5alias glo='git log --oneline --decorate --color'
6
7alias glog='git log --oneline --decorate --color --graph'
8
9alias gls='git shortlog -sn'
10
11alias glst='git shortlog -sn'
git cherry-pick
#
1alias gcp='git cherry-pick'
2
3alias gcpa='git cherry-pick --abort'
4
5alias gcpc='git cherry-pick --continue'