Posted in

GitHub CheatSheet – A Quick Guide for Beginners & Developers

github cheatsheet

This is a complete Git & GitHub Cheatsheet (2025 Edition) — everything you need from setup to collaboration, branching, merging, GitHub usage, and troubleshooting — all in one place

Table of Contents

1. Setup & Configuration

Install Git

# Windows
winget install --id Git.Git -e --source winget

# macOS
brew install git

# Linux (Debian/Ubuntu)
sudo apt install git

Configure Git (First Time)

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
git config --global core.editor "code --wait"   # Use VS Code
git config --global color.ui auto

Check Config

git config --list

2. Create or Clone Repository

Initialize New Repo

git init

Clone Existing Repo

git clone <repo_url>
# Example:
git clone https://github.com/username/repo.git

3. Basic Workflow

Check Status

git status

Add Changes

git add <file>        # Add specific file
git add .             # Add all changes

Commit Changes

git commit -m "Your commit message"

View Commit History

git log
git log --oneline     # Short version
git log --graph --decorate --oneline

4. Branching & Merging

Create Branch

git branch <branch_name>

Switch Branch

git checkout <branch_name>
# or
git switch <branch_name>

Create + Switch

git checkout -b <branch_name>
# or
git switch -c <branch_name>

Merge Branch

git checkout main
git merge <branch_name>

Delete Branch

git branch -d <branch_name>     # Safe delete
git branch -D <branch_name>     # Force delete

5. Remote Repositories (GitHub)

Add Remote

git remote add origin <repo_url>

View Remotes

git remote -v

Push to GitHub

git push -u origin main   # First time
git push                  # Next times

Pull from GitHub

git pull origin main

6. Updating & Syncing

Fetch Latest Changes

git fetch

Pull Updates

git pull

Push Updates

git push

7. Undo & Fix Mistakes

Unstage File

git reset <file>

Undo Last Commit (Keep Changes)

git reset --soft HEAD~1

Undo Last Commit (Remove Changes)

git reset --hard HEAD~1

Revert Commit

git revert <commit_hash>

Checkout Old Version

git checkout <commit_hash> -- <file>

8. Stashing (Temporary Storage)

Save Work

git stash

List Stashes

git stash list

Apply Stash

git stash apply

Drop Stash

git stash drop

9. Git Diff & Logs

Show Changes

git diff

Show Differences Between Commits

git diff <commit1> <commit2>

10. Tags & Releases

Create Tag

git tag <tag_name>
git tag -a <tag_name> -m "Message"

Push Tags

git push origin <tag_name>
git push origin --tags

11. GitHub Collaboration

Fork Repo (On GitHub UI)

Create Pull Request (PR)

  1. Push branch to GitHub.
  2. Go to repo → “Pull Requests” → “New Pull Request”.

Review PR

  • Comment, approve, or request changes.

12. SSH Authentication (Optional)

Generate SSH Key

ssh-keygen -t ed25519 -C "your_email@example.com"

Copy Key

cat ~/.ssh/id_ed25519.pub

Add it to GitHub → Settings → SSH and GPG keys → New SSH Key

Test Connection

ssh -T git@github.com

13. Git Ignore

Create .gitignore file:

node_modules/
.env
.DS_Store
*.log

Add and commit:

git add .gitignore
git commit -m "Add .gitignore"

14. GitHub Pages (Deploy Site)

git branch -M main
git push -u origin main

Then go to:
Repo Settings → Pages → Source: main /root → Save

Your site:

https://<username>.github.io/<repo-name>/

15. Useful Shortcuts

CommandDescription
git initCreate repo
git clone URLClone repo
git statusCheck status
git add .Stage all
git commit -mCommit
git pushPush changes
git pullPull updates
git branchList branches
git checkoutSwitch branch
git mergeMerge
git log --onelineCompact history

16. Troubleshooting

Merge Conflicts

Open files → fix conflicts →

git add .
git commit

Remote Already Exists

git remote remove origin
git remote add origin <new_url>

Push Rejected (Out of Date)

git pull origin main --rebase
git push origin main

17. Advanced Commands

View Who Changed a Line

git blame <file>

Show File at Commit

git show <commit_hash>:<file_path>

Clean Untracked Files

git clean -fd

18. GUI Tools

  • GitHub Desktop (Beginner-friendly)
  • Sourcetree
  • GitKraken
  • VS Code Git Integration

19. GitHub CLI (Optional)

Install

gh auth login

Common Commands

gh repo create
gh pr create
gh pr view
gh pr merge

20. Best Practices

Commit often with clear messages
Use feature branches
Pull before push
Write .gitignore early
Use git stash before switching branches
Never commit credentials (.env)

All CheatSheets view

Checkout other Cheatsheets

  1. Python
  2. JavaScript
  3. HTML
  4. CSS
  5. React

Checkout My YouTube Channel

Read my other Blogs

  1. Top 5 Mistakes Beginners Make While Learning to Code (And How to Avoid Them)
  2. Best Programming Languages to Learn in 2025 (and Why)
  3. Before You Learn Web Development: The Advice No One Gave Me
  4. How to Start Coding in 2025: Beginner’s Roadmap
  5. Why Coding is Important: The Language of the Future
  6. Are Coding and Programming the Same? – The Complete Truth You Need to Know
  7. Will Coding Be Replaced by AI?
  8. C++ Programming: Everything You Need to Know

I’m Shaurya, a developer simplifying tech with tutorials, tools, and projects to help you learn, build, and grow in the world of coding.

Leave a Reply

Your email address will not be published. Required fields are marked *