Git

Basics & Commands

Interactive local ↔ remote simulator + 27 command reference. Start with git init.

Interactive Simulator

LOCAL — My Computer
📁

No repository yet.

Click git init to get started.

REMOTE — GitHub / origin
☁️

Remote not connected yet.

It will sync once you push commits.

terminal log

Run git init to create a repository.

Command Reference

git initSetup

Initialize a new local repository.

git clone <url>Setup

Copy a remote repository to your machine.

git config --global user.nameSetup

Set your name for all commits.

git config --global user.emailSetup

Set your email for all commits.

git statusBasic

Show which files are changed, staged, or untracked.

git add <file>Basic

Stage a specific file → Staging Area.

git add .Basic

Stage ALL changed files at once.

git commit -m "msg"Basic

Snapshot staged files into the local repo.

git logBasic

Show the full commit history.

git diffBasic

Show unstaged changes line by line.

git branchBranch

List all local branches.

git branch <name>Branch

Create a new branch at the current commit.

git checkout <branch>Branch

Switch to an existing branch.

git checkout -b <branch>Branch

Create AND switch to a new branch.

git merge <branch>Branch

Merge another branch into the current branch.

git rebase <branch>Branch

Reapply commits on top of another base commit.

git branch -d <branch>Branch

Delete a branch (safe — only if fully merged).

git remote add origin <url>Remote

Connect your local repo to a remote.

git push origin <branch>Remote

Upload local commits to the remote branch.

git pullRemote

Fetch + merge remote changes into local.

git fetchRemote

Download remote refs WITHOUT merging.

git push -u origin <branch>Remote

Push and set upstream tracking (first push).

git restore <file>Undo

Discard unstaged changes — back to last commit.

git restore --staged <file>Undo

Unstage a file → Working Dir.

git reset HEAD~1Undo

Undo last commit, keep changes as unstaged.

git stashUndo

Temporarily save uncommitted changes.

git stash popUndo

Restore the most recent stash.

git rebase -i HEAD~nAdvanced

Interactively edit, squash, reorder, or drop the last n commits.

git cherry-pick <hash>Advanced

Copy a specific commit from any branch onto the current branch.

git bisect startAdvanced

Begin a binary search through commits to find which one introduced a bug.

git reflogAdvanced

View all HEAD movements — rescue lost commits and deleted branches.

git tag -a <name> -m "msg"Advanced

Create an annotated tag pointing to the current commit — ideal for releases.

git stash listAdvanced

Show all stashed changesets with their index and description.

git clean -fdAdvanced

Remove all untracked files and directories from the working tree.

git diff HEAD~1Advanced

Show changes between the current working tree and the previous commit.