Git Cheatsheet

Essential Git commands and workflow patterns for version control. Copy commands with a click and keep your development workflow smooth.

Basic Commands

git init

Initialize a new Git repository

git clone <url>

Clone a repository

git status

Check status of working directory

git add <file>

Stage changes for commit

git commit -m "message"

Commit staged changes

git push

Push commits to remote

git pull

Pull changes from remote

Branching & Merging

git branch

List all local branches

git branch <name>

Create a new branch

git checkout <branch>

Switch to a branch

git checkout -b <name>

Create and switch to new branch

git merge <branch>

Merge branch into current branch

git branch -d <branch>

Delete a branch

Advanced Operations

git stash

Temporarily store changes

git stash pop

Apply and remove stashed changes

git reset <file>

Unstage changes

git reset --hard HEAD

Discard all local changes

git log

View commit history

git rebase <branch>

Reapply commits on top of another branch

Remote Operations

git remote -v

List remote repositories

git remote add origin <url>

Add a remote repository

git fetch

Download objects and refs from remote

git pull --rebase

Pull with rebase instead of merge

git push -u origin <branch>

Push and set upstream branch