ProjectsAboutBookletContact

Git Sheet You Need

A complete quick-reference guide to the most essential Git commands for everyday development.

Git Sheet You Need

Essential Git Commands Cheat Sheet

Whether you are starting a new project or collaborating on a large codebase, these Git commands are essential for everyday version control.

1. Setup & Configuration

Configure your user information which will be attached to your commits.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

2. Starting a Project

Initialize a new local repository or clone an existing one.

# Initialize a new local repository
git init

# Clone a remote repository
git clone <url>

3. Making Changes

Track files, stage changes, and commit them to your history.

# Check the status of your files
git status

# Stage a specific file
git add <file>

# Stage all changes
git add .

# Commit your staged changes with a descriptive message
git commit -m "Description of changes"

4. Branching & Merging

Isolate your work using branches.

# List all local branches
git branch

# Create a new branch
git branch <branch-name>

# Switch to a branch
git checkout <branch-name>
# or using switch (newer)
git switch <branch-name>

# Create and switch to a new branch in one command
git checkout -b <branch-name>

# Merge another branch into your current branch
git merge <branch-name>

5. Sharing & Updating

Synchronize your local repository with a remote server like GitHub or GitLab.

# Add a remote origin
git remote add origin <url>

# Push your commits to the remote branch
git push origin <branch-name>

# Fetch and merge changes from the remote server
git pull origin <branch-name>

6. Inspecting History

View the commit history to see what changes were made.

# View the commit log
git log

# View a concise, one-line summary of commits
git log --oneline

7. Advanced: Reset, Rebase, & Stash

When things go wrong or you need to rewrite history, these are your lifesavers.

# ----- STASHING -----
# Save uncommitted changes temporarily without committing them
git stash

# Apply the most recently stashed changes back to your working directory
git stash pop

# ----- RESETTING -----
# Soft Reset: Undo the last commit, but KEEP your files and changes staged
git reset --soft HEAD~1

# Mixed Reset (Default): Undo the commit and unstage files, but KEEP your changes
git reset HEAD~1

# Hard Reset: DANGER! Completely undo the last commit and DESTROY all changes
git reset --hard HEAD~1

# ----- REBASING -----
# Rebase your current branch onto another (e.g., main) to keep a linear history
git rebase main

# Interactive Rebase: Edit, squash, or reword the last 3 commits
git rebase -i HEAD~3

# Continue a rebase after resolving conflicts
git rebase --continue

Bookmark this guide to quickly look up commands during your development workflow!

KUZURI47

Made by Rahul