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)