Git Cheat Sheet

Complete Git reference including branching, merging, rebasing, and advanced operations. Complete reference guide with copy-paste ready commands.

Basic Commands

git init

Initialize a new Git repository

git clone <url>

Clone a repository

git status

Check working directory status

git add .

Stage all changes

git commit -m "<message>"

Commit staged changes

git push origin <branch>

Push to remote repository

git pull origin <branch>

Pull from remote repository

Branching

git branch

List branches

git branch <name>

Create a new branch

git checkout <branch>

Switch to a branch

git checkout -b <branch>

Create and switch to new branch

git merge <branch>

Merge branch into current branch

git branch -d <branch>

Delete a branch

Advanced

git rebase <branch>

Rebase current branch

git stash

Stash current changes

git stash pop

Apply stashed changes

git reset --hard HEAD~1

Reset to previous commit

git log --oneline

View commit history (compact)