Git Cheatsheet

Essential Git commands and workflows for version control. Quick reference for daily Git operations.

Setup

git init

Initialize a new Git repository

Example:

git init
git clone [url]

Clone a repository from remote

Example:

git clone https://github.com/user/repo.git

Basic

git status

Check status of working directory

Example:

git status
git add [file]

Stage file for commit

Example:

git add index.html
git add .

Stage all changes

Example:

git add .
git commit -m "[message]"

Commit staged changes

Example:

git commit -m "Add new feature"

Remote

git push origin [branch]

Push commits to remote

Example:

git push origin main
git pull

Fetch and merge changes from remote

Example:

git pull

Branching

git branch

List all branches

Example:

git branch
git branch [name]

Create a new branch

Example:

git branch feature-login
git checkout [branch]

Switch to a branch

Example:

git checkout develop
git merge [branch]

Merge branch into current branch

Example:

git merge feature-login

History

git log

View commit history

Example:

git log --oneline
git diff

Show changes between commits

Example:

git diff HEAD~1

Advanced

git reset --hard [commit]

Reset to a specific commit

Example:

git reset --hard HEAD~1
git stash

Save changes for later

Example:

git stash save "work in progress"
git stash pop

Apply stashed changes

Example:

git stash pop
git rebase [branch]

Reapply commits on top of another base

Example:

git rebase main

Related Resources

2 items

Compare Options

Frequently Asked Questions

How do I use this git cheatsheet?

Simply find the command you need, click the copy button to copy it to your clipboard, and paste it into your terminal or code editor. Each command includes a description and example to help you understand its usage.

Can I download this cheatsheet?

Currently, this cheatsheet is available online. You can bookmark this page for quick access.