DEV Community

Cover image for What's your most used shortcut?
Fábio Guerreiro for Doctolib Engineering

Posted on

What's your most used shortcut?

As I’m writing this article, I just finished adding two new commands alias to my git config file :

  • git config --global alias.list-old-branches "!git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}'" - to list all the branches that exist on my local repository but have been deleted from remote
  • git config --global alias.clean-old-branches "!git list-old-branches | xargs git branch -D" - to pick the list of branches returned by the previous command and delete them from my local repository

And then it made me think 'How can we improve our productivity with more of these shortcuts? 🤔'

Alt Text

I hope that each one of us has one or more shortcuts added either to our terminal/VSCode/git. So I decided to write this article for it to work as a centralized repository of shortcuts that can easily be shared among us.

It's not convenient to go through the whole history of 'that'-hot-tips channel. Or having to go through individual SO questions, to look for that VSCode shortcut that allows you to run all the tests from a single file.

Hope this article helps everyone, from an experienced programmer to a newbie! And please, add your own shortcuts in the comments.

Take care, BEAR hugs ฅʕ•ᴥ•ʔฅ

Top comments (3)

Collapse
 
gozaruu profile image
Kais Sghari • Edited

Mostly git related:

# resetting, diffing, and logging
alias clean="git reset --hard && git clean -f -d"
alias hard-clean="git clean -f -i -d -x"
alias diff= "git difftool master head"
alias gmbd="git diff $(git merge-base --fork-point master)"
alias gl="git log --oneline"
alias filehistory="git log --follow -- "
alias resetf="git checkout head --"
alias diffp="git diff head^"

# list recent branches and navigate there
alias grb="git branch --sort=-committerdate | head"
alias grb1="grb | awk 'NR==1 {print $1}' | xargs git checkout"
alias grb2="grb | awk 'NR==2 {print $1}' | xargs git checkout"
alias grb3="grb | awk 'NR==3 {print $1}' | xargs git checkout"
alias grb4="grb | awk 'NR==4 {print $1}' | xargs git checkout"
alias grb5="grb | awk 'NR==5 {print $1}' | xargs git checkout"
alias grb6="grb | awk 'NR==6 {print $1}' | xargs git checkout"

# Go forward in commit history, towards particular commit/pointer
# usage: `forward master`
forward() {
  git checkout $(git rev-list --topo-order HEAD.."$*" | tail -1)
}

# surprisingly effective
alias master="git checkout master && git pull"

# try this one yourself
alias wt="curl wttr.in"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
fwuensche profile image
Flavio Wuensche

My favorites are the default git aliases from oh-my-zsh 🔥

# working with branches
gcb='git checkout -b'
gco='git checkout'
gcm='git checkout master'
gmom = git merge origin/master

# handling changes
gaa='git add --all'
glol=(beautiful git log)
gsta='git stash push'
gstaa='git stash apply'
gcam='git commit -a -m'
gd='git diff'

# synchronizing with remote branch
ggpull='git pull origin "$(git_current_branch)"'
ggpush='git push origin "$(git_current_branch)"'
Enter fullscreen mode Exit fullscreen mode
Collapse
 
pixelastic profile image
Tim Carry

Let's see...
cat ~/.history | cut -d ';' -f2 | sort | uniq -c | sort -nr | head gives me my most used commands.

In there I have the classic alias for git status, git diff with colors, going back to the repo root.

But my favorites are those small hacks to type even less characters. I added one-letter aliases to some of the most used commands: l for ls, c for cat, v for vim, f for fd, g for rg, w for which, y for yarn, etc