Reference

Git

Inspect, save, combine and recover work with clear command effects.

Scope and conventions

Modern Git CLI, including switch and restore (Git 2.23+). Independent examples use illustrative paths and branch names. Inspect status and diffs before changing files or history. Commands below are reference material, not executed by this guide.

Branches & remotes

Create and switch branches

Git

A branch names a commit. switch -c creates and checks out a branch. Switching updates the index and working tree as allowed; incompatible local edits can block it.

Fragment

Git · Create and switch branches
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git branch --list
git switch -c feature/input
git switch main

Recognize detached HEAD

Git

Detached HEAD names a commit directly rather than a branch. A new commit can be retained by creating a branch before leaving it.

Fragment

Git · Recognize detached HEAD
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git switch --detach HEAD~1
# To retain work from this position:
git switch -c investigation

Distinguish a remote from its tracking refs

Git

origin is a conventional remote name, not a special server type. origin/main is a local remote-tracking reference updated by fetching.

Fragment

Git · Distinguish a remote from its tracking refs
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git remote -v
git branch -vv
git remote show origin

Fetch without integrating

Git

fetch downloads objects and updates the configured remote-tracking refs. It does not merge those changes into the current branch.

Fragment

Git · Fetch without integrating
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git fetch origin
git log --oneline HEAD..origin/main
git diff HEAD origin/main

Effect: fetched objects/refs change; your checked-out files are not integrated.

Make the integration policy explicit

Git

pull fetches and then integrates. --ff-only accepts an update only when the current branch can fast-forward.

Fragment

Git · Make the integration policy explicit
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git pull --ff-only

A divergent branch needs an explicit merge or rebase decision; pull does not always mean merge.

Publish a branch

Git

push sends objects and requests remote ref updates. -u records an upstream for later commands.

Fragment

Git · Publish a branch
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git push -u origin feature/input

Remote policy can reject an update. Bare --force-with-lease compares against your remote-tracking ref, which a background fetch can silently update; add --force-if-includes (or set push.useForceIfIncludes), or name the expected value with --force-with-lease=<ref>:<sha>. It still rewrites history; agree on that workflow first.

Name a release point

Git

An annotated tag stores a message and metadata. Tags do not advance when new commits are created.

Fragment

Git · Name a release point
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git tag -a v1.0.0 -m "Version 1.0.0"
git show v1.0.0
git push origin v1.0.0

Rename or remove a local branch

Git

branch -m renames a branch; -d deletes one only when Git’s merge checks permit it. -D bypasses that check. Deleting a branch name does not remove arbitrary working files.

Fragment

Git · Rename or remove a local branch
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git branch -m old-name new-name
git branch -d finished-feature

Switch away before deleting a checked-out branch; other worktrees can also hold it.

Create a tracking branch and inspect its upstream

Git

A local branch can track a remote-tracking branch. The upstream supplies defaults for selected status, pull and push behavior, subject to configuration.

Fragment

Git · Create a tracking branch and inspect its upstream
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git fetch origin
git switch -c feature --track origin/feature
git branch -vv
git branch --set-upstream-to=origin/feature feature

Remote-tracking references are local observations updated by fetch; they are not live server branches.

Add a remote or change its URL

Git

A remote is a named set of fetch/push configuration. Adding it or changing its URL does not move the local branch or integrate remote history.

Fragment

Git · Add a remote or change its URL
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git remote add upstream https://example.test/team/project.git
git remote get-url upstream
git remote set-url upstream https://example.test/new/project.git

Names and URLs are examples. Separate fetch and push URLs are supported when that workflow is intentional.