DEV Community

Cover image for ๐Ÿš€ Supercharge Your Git Workflow in Bash: Autocomplete, Aliases & Pro Tips
Vansh Chaurasiya
Vansh Chaurasiya

Posted on

๐Ÿš€ Supercharge Your Git Workflow in Bash: Autocomplete, Aliases & Pro Tips

If you're a developer spending time in the terminal, chances are you use Git daily. But are you using Git efficiently?

In this guide, weโ€™ll unlock the hidden power of Git in the Bash terminal:

  • โœ… Set up Git autocompletion ๐Ÿง 
  • โšก Use shortcut aliases for super speed ๐Ÿงจ
  • ๐Ÿงฉ Learn extra Git and Bash tricks for a smoother developer life

Letโ€™s elevate your terminal game. ๐Ÿง‘โ€๐Ÿ’ป๐Ÿ’ฅ


๐Ÿง  1. Enable Git Autocompletion

Ever typed git chec<TAB> and wished it would magically suggest checkout? Thatโ€™s exactly what Git autocompletion does.

๐Ÿ”ง Step-by-step setup:

  1. Download the Git completion script (straight from the official repo):
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
Enter fullscreen mode Exit fullscreen mode
  1. Source it in your .bashrc file:
echo 'source ~/.git-completion.bash' >> ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
  1. Reload your Bash config:
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

โœจ Done! Now your terminal understands Git commands and their options. Try typing git ch<TAB> to see the magic!


โšก 2. Setup Super Useful Git Aliases in .bashrc

Typing full Git commands over and over is slow and tedious. Letโ€™s speed things up with aliases.

Here are battle-tested aliases you can paste into your .bashrc:

alias cls="clear"

alias gs="git status -s"
alias gl="git log --graph --pretty=format:'%C(magenta)%h %C(white)%an %ar%C(auto)%D%n%s%n'"

alias gco='git checkout'
__git_complete gco _git_checkout

alias gfo='git fetch origin'
__git_complete gfo _git_fetch

alias gcb='git checkout -b'

alias gsw="git switch"
__git_complete gsw _git_switch

alias ga="git add"
__git_complete ga _git_add

alias gc="git commit"
__git_complete gc _git_commit

alias gp="git push"
__git_complete gp _git_push

alias gpl="git pull"
__git_complete gpl _git_pull

alias gplr="git pull --rebase"

alias gb="git branch"
__git_complete gb _git_branch

alias gbd="git branch -D"
alias gbm="git branch -m"

alias gd="git diff"

alias gst="git stash"
alias gsl="git stash list"
alias gsp="git stash pop"
alias gsa="git stash apply"
alias gsd="git stash drop"
alias gspm="git stash push -m"
Enter fullscreen mode Exit fullscreen mode

Now instead of typing git status, just do:

gs
Enter fullscreen mode Exit fullscreen mode

Or switch branches with:

gco feature/login
Enter fullscreen mode Exit fullscreen mode

โœ… Pro tip: Aliases with __git_complete also support auto-suggestions for branch names!


๐Ÿ”„ 3. Improve History Navigation (Bonus Bash Tricks)

These tweaks help make your terminal feel more like a supercharged IDE.

๐Ÿ”น Add this to your .bashrc:

HISTCONTROL=ignoredups:erasedups
HISTSIZE=10000
HISTFILESIZE=20000
shopt -s histappend

# Arrow up/down searches through command history
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
Enter fullscreen mode Exit fullscreen mode

Now typing git <โ†‘> will search your previous Git commands!


๐Ÿ› ๏ธ 4. More Bash Productivity Aliases

Beyond Git, here are a few handy Bash aliases to help you zoom through your terminal:

alias ..='cd ..'
alias ...='cd ../..'
alias +='cd'
alias x='exit'
alias reload='source ~/.bashrc'

alias ni="npm install"
alias nrd="npm run dev"
alias nrb="npm run build"
Enter fullscreen mode Exit fullscreen mode

๐Ÿš€ nrd instead of npm run dev?
YES, PLEASE.


๐Ÿ” Final Touch: Reloading .bashrc

After adding all of this to your .bashrc, donโ€™t forget to reload your terminal:

source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Or just run:

reload
Enter fullscreen mode Exit fullscreen mode

(if youโ€™ve added that alias ๐Ÿ˜‰)


๐Ÿงช Want to Go Further?

Here are some ideas to take this even further:

  • Add fzf to interactively switch branches.
  • Use tools like lazygit for a TUI Git experience.
  • Integrate delta for beautiful diffs.
  • Add Git hooks for pre-commit validations.
  • Explore gh CLI for GitHub magic.

๐Ÿš€ Wrap Up: Your Git-Boosted Bash Terminal

You just:

  • Supercharged Git with autocomplete
  • Boosted productivity with aliases
  • Polished your terminal experience with bonus tricks

This setup not only saves keystrokes but helps you focus on what really matters: building great software.


๐Ÿ’ฌ Did this boost your Git game?
Drop your favorite Git/Bash alias below or share the ones you canโ€™t live without!

๐Ÿ“Œ Bookmark this post and level up every new machine you set up.

๐Ÿ—ฃ๏ธ I'd Love to Hear From You

Have you customized your Git/Terminal in a cool way? Got tips to share? Drop them in the comments or DM me on X (Twitter) โ€“ let's inspire more productive terminals together ๐Ÿ’ฌ

X - Linkedin - GitHub - Portfolio

Top comments (0)