Git Essentials

Version: 2.xPublished: 2026-01-16git/core

Essential git commands for day-to-day development.

Setup

ExampleDescription
git config --global user.name "Your Name"
Set identity
Configure your name for commits (also set user.email).
git config --global init.defaultBranch main
Set default branch
Use 'main' as the default branch for new repos.

Inspect

ExampleDescription
git status
Status
Show staged, unstaged, and untracked files.
git log --oneline --graph -10
Log
View recent commit history in compact format.
git diff --staged
Diff
Show changes staged for the next commit.
git blame path/to/file.ext
Blame
Show who last modified each line of a file.

Stage & Commit

ExampleDescription
git add .
Stage all
Stage all changes in current directory.
git add -p
Stage interactively
Stage changes hunk by hunk.
git restore --staged file.ext
Unstage
Remove file from staging area, keep changes.
git commit -m "Add feature"
Commit
Create a commit with staged changes.
git commit --amend
Amend
Modify the last commit (message or content).

Branches

ExampleDescription
git switch -c feature/new-thing
Create & switch
Create a new branch and switch to it.
git switch main
Switch
Switch to an existing branch.
git branch -vv
List
List branches with upstream tracking info.
git branch -d feature/done
Delete
Delete a merged branch (-D to force).

Remote

ExampleDescription
git clone git@github.com:org/repo.git
Clone
Download a repository and its history.
git fetch --prune
Fetch
Download refs and clean up deleted remote branches.
git pull --rebase
Pull
Fetch and rebase local commits on top.
git push -u origin feature/branch
Push
Push branch and set upstream tracking.

Merge & Rebase

ExampleDescription
git merge feature/branch
Merge
Merge another branch into current branch.
git rebase origin/main
Rebase
Replay commits on top of another base.
git rebase --continue
Continue rebase
Continue after resolving conflicts.
git cherry-pick abc123
Cherry-pick
Apply a specific commit to current branch.

Stash

ExampleDescription
git stash push -m "wip"
Save
Temporarily save uncommitted changes.
git stash list
List
Show all stashed changes.
git stash pop
Apply
Restore and remove most recent stash.

Undo

ExampleDescription
git restore file.ext
Discard changes
Discard working tree changes to a file.
git revert HEAD
Revert commit
Create a new commit that undoes a previous one.
git reset --soft HEAD~1
Reset soft
Undo last commit, keep changes staged.
git reflog
Reflog
Show history of HEAD movements for recovery.