Code & computing / QUICK REFERENCE

Everyday Git

A practical reference for inspecting changes, making commits, navigating history and working with branches.

32 entries

Inspect before you change

Working tree overview
git status

Shows staged, unstaged and untracked paths. [2]

Compact status
git status --short

Gives a concise path-by-path summary. [2]

Unstaged changes
git diff

Compares tracked working files with the index. [3]

Staged changes
git diff --cached

Shows exactly what the next commit would include. [3]

Change summary
git diff --stat

Summarizes tracked changes by file. [3]

Check whitespace errors
git diff --check

Reports whitespace errors in the proposed diff. [3]

List tracked files
git ls-files

Untracked paths do not appear here. [4]

Current commit identity
git rev-parse HEAD

Prints the full current commit hash. [5]

Save intentional snapshots

Create a repository
git init

Initializes Git in the current directory. [6]

Stage one file
git add notes.txt

Stages the file's current contents. [7]

Stage selected hunks
git add -p

Interactively chooses pieces to stage. [7]

Commit staged changes
git commit -m "Describe the change"

Commits the index, not every working-tree edit. [8]

Show configured identity
git var GIT_AUTHOR_IDENT

Displays the identity Git will use. [9]

Repository root
git rev-parse --show-toplevel

Locates the working tree's top directory. [5]

Clone a repository
git clone https://github.com/OWNER/REPO.git

Downloads a repository into a new directory. [10]

Ignore-file location
.gitignore

Store ignore patterns here; already tracked files remain tracked. [11]

Branches and cautious synchronization

List local branches
git branch

Marks the active branch with an asterisk. [12]

Show branch tracking
git branch -vv

Includes upstream relationships when configured. [12]

Create and switch
git switch -c feature-notes

Starts a branch from the current commit. [13]

Switch to an existing branch
git switch main

May refuse if local changes would be overwritten. [13]

Return to previous branch
git switch -

Returns to the previous checkout target. [13]

List remote addresses
git remote -v

Verify destinations before fetching or pushing. [14]

Fetch remote updates
git fetch origin

Updates remote-tracking refs without merging into your branch. [15]

Fast-forward only merge
git merge --ff-only origin/main

Refuses a merge that would need a merge commit. [16]

Read the history

Recent commits
git log --oneline -5

Shows five compact commit summaries. [17]

Branch graph
git log --graph --oneline --decorate --all

Displays the relationship between reachable commits. [17]

Show one commit
git show HEAD

Displays the current commit and its patch. [18]

History for a file
git log -- notes.txt

Restricts history to that path. [17]

Follow a renamed file
git log --follow -- notes.txt

Follows one file through detectable renames. [17]

Find commit messages
git log --grep="fix"

Searches commit messages, not source contents. [17]

Who last changed each line
git blame -- notes.txt

Attributes lines to commits; it is not proof of authorship quality. [19]

Recent reference movements
git reflog -10

Helps inspect local moves; it is not a remote backup. [20]

Reserved placement, separate from reference controls. No ad network is active.

Updated Git CLI · local and remote workflows

Sources

  1. Git tutorial ↗
  2. Git status reference ↗
  3. Git diff reference ↗
  4. Git ls-files reference ↗
  5. Git rev-parse reference ↗
  6. Git init reference ↗
  7. Git add reference ↗
  8. Git commit reference ↗
  9. Git var reference ↗
  10. Git clone reference ↗
  11. Git gitignore reference ↗
  12. Git branch reference ↗
  13. Git switch reference ↗
  14. Git remote reference ↗
  15. Git fetch reference ↗
  16. Git merge reference ↗
  17. Git log reference ↗
  18. Git show reference ↗
  19. Git blame reference ↗
  20. Git reflog reference ↗