Git Command Cheat Sheet

Quick reference for the most common Git commands

Getting Started

Check Git version

bash
git --version

Set your name

bash
git config --global user.name "Your Name"

Set your email

bash
git config --global user.email "you@example.com"

Basic Commands

Create a new repository

bash
git init

Check status of files

bash
git status

Add all files to staging

bash
git add .

Add specific file

bash
git add <filename>

Save changes with a message

bash
git commit -m "message"

View commit history

bash
git log

View compact history

bash
git log --oneline

Working with Branches

List all branches

bash
git branch

Create new branch

bash
git branch <name>

Switch to branch

bash
git checkout <name>

Create and switch to new branch

bash
git checkout -b <name>

Merge branch into current branch

bash
git merge <branch>

Delete branch

bash
git branch -d <name>

Working with GitHub

Download a repository

bash
git clone <url>

Connect local repo to GitHub

bash
git remote add origin <url>

Upload changes to GitHub

bash
git push origin main

Push and set upstream

bash
git push -u origin main

Download latest changes

bash
git pull

Pull from specific branch

bash
git pull origin main

View remote repositories

bash
git remote -v

Useful Commands

Show unstaged changes

bash
git diff

Show staged changes

bash
git diff --staged

Unstage a file

bash
git reset <file>

Discard changes in file

bash
git checkout -- <file>

Temporarily save changes

bash
git stash

Restore stashed changes

bash
git stash pop

Tip

Don't try to memorize all commands at once! Copy the ones you need and practice them regularly. They'll become natural with time.