Quick reference

Git reference

Setup, daily commands, history recovery and team workflows.

Git records snapshots and relationships. Commit small, meaningful changes, inspect the diff before committing and use branches to isolate work that is not ready for main. When something goes wrong, prefer restore or revert over rewriting history you have already shared.

Read the full explanationGit & GitHub

Work through the guided lesson, then test yourself with a challenge.

Open course
141 entries

Branches and integration

Branches and merges

Everyday workflow

History and recovery

Hooks

Inspection

git blame -L

git blame -L <start>,<end> <file>

Limits blame to a line range.

Open entry

git cat-file

git cat-file -p <object>

Prints the contents of any Git object: commit, tree, blob or tag.

Open entry

git count-objects

git count-objects -v

Reports loose object counts and repository size.

Open entry

git diff --check

git diff --check

Reports whitespace errors such as trailing spaces and conflict markers.

Open entry

git diff --stat

git diff --stat

A summary of changed files and line counts.

Open entry

git diff --word-diff

git diff --word-diff

Highlights changed words instead of whole lines, which is easier for prose.

Open entry

git for-each-ref

git for-each-ref

Iterates refs with formatting, great for scripting branch reports.

Open entry

git fsck

git fsck

Checks repository integrity and reports dangling or corrupt objects.

Open entry

git hash-object

git hash-object <file>

Computes the object id Git would use for a file.

Open entry

git log --author

git log --author=<name>

Filters history by author.

Open entry

git log --follow

git log --follow <path>

Follows a file across renames.

Open entry

git log --since

git log --since="2 weeks ago"

Filters commits by date.

Open entry

git log --stat

git log --stat

Shows changed files and line counts per commit.

Open entry

git log -p

git log -p

Shows history with the full patch of each commit.

Open entry

git log -S

git log -S<string>

Finds commits that added or removed a string, also known as pickaxe.

Open entry

git ls-tree

git ls-tree <tree>

Lists the contents of a tree object.

Open entry

git rev-list

git rev-list --count <range>

Lists or counts commits reachable from a revision.

Open entry

git shortlog -sn

git shortlog -sn

A commit count per author, useful for release notes.

Open entry

git show --stat

git show --stat <ref>

Shows a commit with a file summary instead of the full patch.

Open entry

git verify-pack

git verify-pack -v <pack>

Inspects the contents and sizes of a packfile.

Open entry

Inspection and internals

Maintenance

Patches and plumbing

Rewriting and tagging

Setup and configuration

Setup and remotes

git clone --branch

git clone --branch <name> <url>

Clones a specific branch and checks it out.

Open entry

git clone --depth

git clone --depth 1 <url>

A shallow clone with limited history. Faster for CI, but blame and log are incomplete.

Open entry

git config alias

git config --global alias.st status

Creates a shortcut for a command or a longer option combination.

Open entry

git config core.autocrlf

git config --global core.autocrlf input

Controls line-ending conversion across Windows and Unix.

Open entry

git config pull.rebase

git config --global pull.rebase true

Makes git pull rebase local commits instead of creating merge commits.

Open entry

git init --bare

git init --bare repo.git

Creates a repository without a working tree, used as a server-side remote.

Open entry

git remote add

git remote add <name> <url>

Adds a named remote, such as upstream for the original repository.

Open entry

git remote remove

git remote remove <name>

Removes a remote and its tracking branches.

Open entry

git remote set-url

git remote set-url origin <url>

Changes the URL of an existing remote.

Open entry

git remote show

git remote show origin

Shows fetch and push URLs, tracked branches and remote HEAD.

Open entry

git sparse-checkout

git sparse-checkout set <paths>

Checks out only selected paths in a large monorepo.

Open entry

git submodule add

git submodule add <url> <path>

Adds another repository as a submodule at a path.

Open entry

git submodule status

git submodule status

Lists submodules with their pinned commits.

Open entry

git submodule update

git submodule update --init --recursive

Fetches and checks out submodule commits after cloning.

Open entry

Sharing and syncing

Snapshot and staging

Keep going

Turn the reference into recall.

Read the full lesson, then solve the challenge without looking. That is where the knowledge sticks.