Home / Commands
Command guide

Find the next safe step

A task-oriented command reference. Search by command or outcome, then inspect the change before you record or discard it.

35 commands
start

Start a repository

Create a local history or obtain an existing one.

git init

Start a Git repository in the current directory.

git clone URL

Copy a repository, including its history.

hg init

Start a Mercurial repository.

svn checkout URL

Get a working copy from a Subversion server.

fossil init project.fossil

Create a Fossil repository file.

fossil open project.fossil

Open that repository in the current directory.

inspect

Inspect before you change

See the working tree, staged content, and history.

git status --short

A compact view of changed, staged, and untracked files.

git diff

Inspect unstaged edits.

git diff --staged

Inspect what the next commit would contain.

git log --oneline --graph --decorate -20

Read a compact graph of recent commits.

hg status

Show Mercurial working-copy changes.

svn status

Show Subversion working-copy changes.

record

Record useful changes

Make a commit that describes one coherent step.

git add -p

Choose individual hunks for the staging area.

git commit -m "Explain the change"

Record staged content with a clear message.

hg commit -m "Explain the change"

Record a Mercurial changeset.

svn commit -m "Explain the change"

Send a Subversion revision to the server.

fossil commit -m "Explain the change"

Record a Fossil check-in.

branches

Work on another line

Keep parallel work legible without losing your place.

git switch -c feature/name

Create and switch to a new Git branch.

git switch main

Return to the main branch (if it is named main).

git worktree add -b feature/name ../feature main

Create a second working tree on a new branch.

git merge feature/name

Bring another branch into the current one.

hg bookmark feature

Create a movable Mercurial bookmark.

hg update feature

Update the working directory to that bookmark.

share

Synchronize with others

Local history and shared history are separate steps in distributed tools.

git fetch --prune origin

Refresh remote-tracking references and remove stale ones.

git pull --ff-only

Update the current branch only when a fast-forward is possible.

git push -u origin feature/name

Publish a branch and set its upstream.

hg pull -u

Pull changes and update the working directory.

hg push

Publish Mercurial changesets to a destination.

svn update

Update a Subversion working copy from its server.

recover

Undo and investigate

Prefer operations that keep published history intact.

git restore --staged path/to/file

Unstage a file while keeping its working-tree edits.

git restore path/to/file

Discard local edits to a file. Check the diff first.

git revert COMMIT

Create a new commit that reverses a previous commit.

git reflog

Find recent positions of local references after a mistake.

git bisect start

Begin narrowing down the commit that introduced a bug.

git blame -- path/to/file

See the last recorded change for each line.

Before destructive operations: inspect git status and git diff. git restore path/to/file discards uncommitted edits; git revert is usually the safer way to undo a published commit.