If you’re using Oh My Zsh, you have access to a powerful set of git aliases that can significantly speed up your development workflow. The git plugin comes pre-installed and provides dozens of shortcuts for common git operations.

Essential Git Aliases

Here are the most useful git aliases that will transform your daily workflow:

Basic Operations

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Status and information
gst     # git status
gss     # git status --short
gsb     # git status --short --branch
gl      # git pull
gp      # git push
ga      # git add
gaa     # git add --all
gc      # git commit --verbose
gcmsg   # git commit --message
gca     # git commit --verbose --all
gcam    # git commit --all --message

# Branch operations
gb      # git branch
gba     # git branch --all
gbd     # git branch --delete
gcb     # git checkout -b
gco     # git checkout
gcm     # git checkout $(git_main_branch)
gcd     # git checkout $(git_develop_branch)

Advanced Workflow

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Logging and history
glog    # git log --oneline --decorate --graph
gloga   # git log --oneline --decorate --graph --all
glol    # git log --graph --pretty=format with colors
glola   # git log --graph --pretty=format with colors --all
glo     # git log --oneline --decorate
glg     # git log --stat
glgp    # git log --stat --patch

# Stashing
gsta    # git stash push (or save on older git)
gstp    # git stash pop
gsts    # git stash show --patch
gstd    # git stash drop
gstl    # git stash list
gstaa   # git stash apply
gstc    # git stash clear

# Merging and rebasing
gm      # git merge
gma     # git merge --abort
gmc     # git merge --continue
grb     # git rebase
grba    # git rebase --abort
grbc    # git rebase --continue
grbi    # git rebase --interactive

Remote Operations

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Remote management
gr      # git remote
grv     # git remote --verbose
gra     # git remote add
grrm    # git remote remove
grmv    # git remote rename
grset   # git remote set-url

# Fetching and pulling
gf      # git fetch
gfa     # git fetch --all --tags --prune
gfo     # git fetch origin
gpr     # git pull --rebase
gpra    # git pull --rebase --autostash
gpu     # git push upstream
gpv     # git push --verbose

Diff and Show

1
2
3
4
5
6
7
# Diff operations
gd      # git diff
gdca    # git diff --cached
gds     # git diff --staged
gdw     # git diff --word-diff
gdt     # git diff-tree --no-commit-id --name-only -r
gsh     # git show

My Most Used Aliases

Based on daily development work, here are the aliases I use most frequently:

  1. gss - Quick status check
  2. gaa - Add all changes
  3. gcmsg "message" - Add all and commit with message
  4. gp - Push changes
  5. gco branch-name - Switch branches
  6. gcb new-branch - Create and switch to new branch
  7. glog - Beautiful git log
  8. gsta - Stash changes quickly
  9. gstp - Pop stashed changes
  10. gl - Pull latest changes

Common Workflow Examples

Starting a new feature:

1
2
3
gcm               # Switch to main branch
gl                # Pull latest changes
gcb feature-xyz   # Create and switch to new branch

Daily commit workflow:

1
2
3
4
gss                     # Check status
gaa                     # Add all changes
gcmsg "Add new feature" # Commit with message
gp                      # Push to remote

Reviewing changes:

1
2
3
gd                # Show unstaged changes
gdca              # Show cached/staged changes
glog              # Review commit history

Working with stash:

1
2
3
4
5
gsta              # Stash current changes
gco other-branch  # Switch to other branch
# ... do some work
gco original-branch # Switch back
gstp              # Pop stashed changes

Enabling the Git Plugin

If you don’t have the git plugin enabled, add it to your ~/.zshrc:

1
plugins=(git)

Advanced Aliases

Reset and Restore Operations

1
2
3
4
5
grh     # git reset
grhh    # git reset --hard
grhs    # git reset --soft
grs     # git restore
grst    # git restore --staged

Pro Tips

  1. Use gss for a short status format that’s easier to read
  2. Combine aliases: gaa && gcmsg "Quick fix" && gp for rapid commits
  3. Use gsta and gstp for quick context switching
  4. glog vs glol - try both to see which format you prefer
  5. Learn grbi for interactive rebasing - it’s a game changer
  6. Use gpr instead of gl when you want to rebase instead of merge

Creating Custom Aliases

You can also create your own aliases in your ~/.zshrc:

1
2
3
4
5
# Custom git aliases
alias gundo='git reset --soft HEAD~1'
alias gclean='git clean -fd'
alias gwip='git add -A && git commit -m "WIP"'
alias gfresh='git fetch --all && git reset --hard origin/$(git_current_branch)'

Main vs Master Branch

Oh My Zsh intelligently detects whether your repository uses main or master as the default branch. The gcm alias will switch to whichever is configured as your main branch.

Conclusion

Oh My Zsh git aliases can dramatically improve your development speed. Start with the basic ones (gst, gaa, gcam, gp) and gradually incorporate more advanced aliases into your workflow. Your future self will thank you for the time saved!

Remember: the key is consistency. Pick a set of aliases and use them regularly until they become muscle memory.