By admin , 28 April 2026

Introduction

Git rewards command-line fluency. A few small habits make day-to-day work dramatically faster and safer. This page collects the highest-impact tips for new users.

Always know where you are

Add Git status to your shell prompt. Bash and Zsh both ship contrib scripts:

# bash
source /usr/share/git/completion/git-prompt.sh
PS1='\w$(__git_ps1 " (%s)")\$ '

# zsh with oh-my-zsh: enable the git plugin in ~/.zshrc

Now the current branch and dirty state are visible at all times.

Tab completion

Git ships git-completion.bash; most package managers install it automatically. Tab-complete commands, branches, remotes, and refs:

git che<TAB>
git switch fea<TAB>

Aliases that pay off

git config --global alias.s "status -sb"
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.co switch
git config --global alias.last "log -1 HEAD --stat"
git config --global alias.unstage "restore --staged"

Shorter status

git status -sb

The -sb form is two-column and includes branch tracking info; perfect for quick checks.

Better diffs

git diff --word-diff
git diff --color-words
git config --global diff.colorMoved zebra

colorMoved=zebra highlights moved blocks of code differently from added/removed ones, making refactors easier to review.

Useful environment

  • Set GIT_PAGER=less -FRX for sensible paging.
  • Set EDITOR to something you know how to quit.
  • Use a credential helper: git config --global credential.helper cache on Linux, osxkeychain on macOS, manager on Windows.

Safe defaults

git config --global pull.ff only
git config --global push.autoSetupRemote true
git config --global fetch.prune true
git config --global rerere.enabled true

rerere ("reuse recorded resolution") remembers how you solved a conflict and replays it next time.

Reading commit history at speed

Two viewing tricks pay off daily:

git log --oneline --graph --all --decorate
git log -p --follow path/to/file
git show HEAD --stat
git diff @{u}                  # vs upstream
git diff @{1.day.ago}          # vs HEAD a day ago

Every Git command that takes a commit accepts the same revision syntax: branch names, SHAs, HEAD~3, @{upstream}, @{2.hours.ago}, tag^{commit}. Learn it once via git help gitrevisions and use it everywhere.

Common mistakes

Copy-pasting long commands from blog posts without understanding them; read git help <cmd> for any unfamiliar flag. Aliasing destructive commands to short names (r = reset --hard) and triggering them by accident; reserve short aliases for safe operations. Ignoring shell tab-completion and typing branch names by hand, with all the typos that implies. Finally, never paste shell output into a commit message expecting it to render as code; use a code block in your editor or commit a file instead. Small habits compound; invest one afternoon configuring your shell and reap years of benefit.