Setup & Config
Set User Name
Set the name you want attached to your commit transactions.
git config --global user.name "Your Name"Set User Email
Set the email you want attached to your commit transactions.
git config --global user.email "email@example.com"Initialize Repository
Create a new local repository.
git initClone Repository
Download a project and its entire version history.
git clone <url>Basic Snapshotting
Check Status
List which files are staged, unstaged, and untracked.
git statusAdd Files
Stage changes for the next commit.
git add <file>
# or stage all changes
git add .Commit Changes
Commit your staged content as a new snapshot.
git commit -m "Commit message"View History
Show the commit history for the currently active branch.
git logBranching & Merging
List Branches
List all local branches in the current repository.
git branchCreate Branch
Create a new branch.
git branch <branch-name>Switch Branch
Switch to the specified branch and update the working directory.
git checkout <branch-name>
# or
git switch <branch-name>Create & Switch
Create a new branch and switch to it.
git checkout -b <branch-name>Merge Branch
Merge the specified branch's history into the current one.
git merge <branch-name>Inspection & Comparison
Diff
Show changes between commits, commit and working tree, etc.
git diffDiff Staged
Show changes between the staging area and the last commit.
git diff --stagedUndoing Changes
Discard Changes
Discard changes in the working directory.
git checkout -- <file>
# or
git restore <file>Unstage File
Remove a file from the staging area.
git reset HEAD <file>
# or
git restore --staged <file>Amend Commit
Replace the last commit with the staged changes and last commit combined.
git commit --amend