Safe sandbox
LEARN BY DOING

Git Command Reference for Beginners

See what happens behind every command.

EXPLORE · EXPERIMENT · UNDERSTAND

A command for every moment.

19 commands found

git remote add origin <url>

Give an existing remote repository the nickname origin.

Create an empty GitHub repository first, then use its URL. This does not upload files.
Explore this lesson
git init -b main

Turn a folder into a Git repository; name the first branch main.

Run once when starting a new local project.
Explore this lesson
git clone <url>

Download a repository and its history.

Creates a local copy with origin configured.
Explore this lesson
git status

Inspect your branch, staged changes, and unstaged changes.

A useful first step whenever you feel lost.
Explore this lesson
git diff

See the changes between working files and the staging area.

Use git diff --staged to inspect your next commit.
Explore this lesson
git add <file>

Stage the file’s current content for the next snapshot.

If you edit it again, stage it again to include that edit.
Explore this lesson
git commit -m "message"

Record the staged snapshot in your local history.

A commit does not publish anything to GitHub.
Explore this lesson
git switch -c feature

Create a branch and start working on it.

The new branch initially points to your current commit.
Explore this lesson
git switch main

Switch your working files and HEAD to main.

Save or stash changes before switching when necessary.
Explore this lesson
git merge feature

Integrate feature into your current branch.

Can fast-forward, create a merge commit, or stop at conflicts.
Explore this lesson
git fetch origin

Download history and refresh remote-tracking branches.

Does not integrate changes into your current branch.
Explore this lesson
git pull --ff-only origin main

Fetch and update your current branch only if it can fast-forward.

Diverged branches require an explicit merge or rebase decision.
Explore this lesson
git push -u origin feature

Publish feature and set its upstream tracking branch.

Push can be rejected if the remote has incompatible updates.
Explore this lesson
git log --oneline

Read the commits reachable from your current branch.

Each short ID identifies a saved snapshot.
Explore this lesson
git revert HEAD

Create a new commit that reverses the latest commit.

Suitable for undoing a mistake in shared history.
Explore this lesson
git restore <file>

Discard unstaged edits in a tracked file.

Destructive: check git diff first. Not simulated here.
Explore this lesson
git restore --staged <file>

Remove a file’s changes from the staging area.

Keeps the edits in your working directory.
Explore this lesson
git stash

Temporarily save local changes for later.

Use git stash pop to reapply them; conflicts can occur.
Explore this lesson
git reset --soft HEAD~1

Move the branch back one commit, keeping changes staged.

Rewrites the local branch. Avoid changing shared history.
Explore this lesson