🚀 Complete Git & GitHub Guide

Installation, Setup, and Master Essential Git Commands

💻 How to Install Git

💡 Quick Tip

Choose your operating system and follow the steps. Installation takes just 5 minutes!

Windows Installation
1
Download Git Installer
Visit https://git-scm.com/ and click the "Download for Windows" button.
The file will be named something like Git-2.x.x-64-bit.exe
2
Run the Installer
Double-click the downloaded .exe file to start installation.
3
Follow Installation Wizard
Click "Next" through all the setup screens. Don't worry about the options - the default settings are perfect for beginners!
4
Complete Installation
Click "Finish" when the installation completes. Git is now installed!
5
Verify Installation
Open "Command Prompt" or "PowerShell" and type:
git --version
You should see: git version 2.x.x.windows.1
Git is Installed!

You've successfully installed Git on Windows. Ready to move on! 🎉

Mac Installation
1
Method 1: Using Homebrew (Recommended)
Open Terminal and type:
brew install git
Don't have Homebrew? Install it from https://brew.sh/
2
Method 2: Download Installer
Visit https://git-scm.com/, download for Mac, and double-click to install.
3
Method 3: Xcode Command Line Tools
Open Terminal and type:
xcode-select --install
4
Verify Installation
Open Terminal and type:
git --version
Git is Ready on Mac!

Git is now installed and configured. Let's set it up! 🎉

Linux Installation
1
Ubuntu / Debian-based
Open Terminal and type:
sudo apt update sudo apt install git
2
Fedora / RedHat-based
Open Terminal and type:
sudo dnf install git
3
Arch Linux
Open Terminal and type:
sudo pacman -S git
4
Verify Installation
Type in Terminal:
git --version
Git is Installed on Linux!

You're all set. Time to configure Git! 🎉

⚙️ First Time Setup (All Operating Systems)

1
Set Your Name
This will appear in all your commits:
git config --global user.name "Your Full Name"
Example: git config --global user.name "John Doe"
2
Set Your Email
Use the same email as your GitHub account:
git config --global user.email "your.email@example.com"
Example: git config --global user.email "john@example.com"
3
Verify Your Settings
Check that everything is configured correctly:
git config --list
All Setup Complete!

Git is installed and configured on your computer. You're ready to start using Git! 🚀

🔐 Generate SSH Keys (Secure Connection to GitHub)

💡 Why SSH Keys?

SSH keys are a secure way to connect to GitHub without typing your password every time. It's more secure and convenient!

Generate SSH Key on Windows
1
Open PowerShell as Administrator
Right-click on PowerShell and select "Run as Administrator"
2
Generate SSH Key
Type this command (replace with your email):
ssh-keygen -t ed25519 -C "your.email@example.com"
For older systems: ssh-keygen -t rsa -b 4096 -C "your.email@example.com"
3
Press Enter for Default Location
When asked for file location, just press Enter to save to the default location: .ssh/id_ed25519
4
Create a Passphrase (Optional)
When asked for a passphrase, you can either type one for extra security, or press Enter to skip it. For beginners, skipping is fine.
5
View Your Public Key
Type this to see your public key:
type $env:USERPROFILE\.ssh\id_ed25519.pub
Important: Copy the entire output that starts with "ssh-ed25519"
6
Add Key to GitHub
1. Go to GitHub Settings → SSH and GPG keys
2. Click "New SSH key"
3. Paste your public key from step 5
4. Click "Add SSH key"
SSH Key Added!

Your SSH key is now connected to GitHub. You can push/pull without passwords! 🔐

Generate SSH Key on Mac
1
Open Terminal
Press Cmd + Space, type "Terminal", and press Enter
2
Generate SSH Key
Type this command (replace with your email):
ssh-keygen -t ed25519 -C "your.email@example.com"
For older Macs: ssh-keygen -t rsa -b 4096 -C "your.email@example.com"
3
Press Enter for Default Location
When prompted, press Enter to save to: ~/.ssh/id_ed25519
4
Create a Passphrase (Optional)
Enter a passphrase for security, or press Enter to skip. For beginners, you can skip this.
5
Start SSH Agent
Type this to start the SSH agent:
eval "$(ssh-agent -s)"
6
Add Key to SSH Agent
Type this to add your key:
ssh-add ~/.ssh/id_ed25519
7
View Your Public Key
Type this to display your public key:
cat ~/.ssh/id_ed25519.pub
Copy the entire output starting with "ssh-ed25519"
8
Add Key to GitHub
1. Go to GitHub Settings → SSH and GPG keys
2. Click "New SSH key"
3. Paste your public key from step 7
4. Click "Add SSH key"
SSH Key Connected!

Your Mac is now securely connected to GitHub! 🔐

Generate SSH Key on Linux
1
Open Terminal
Press Ctrl + Alt + T to open Terminal
2
Generate SSH Key
Type this command (replace with your email):
ssh-keygen -t ed25519 -C "your.email@example.com"
For older systems: ssh-keygen -t rsa -b 4096 -C "your.email@example.com"
3
Press Enter for Default Location
When asked for file location, press Enter to save to: ~/.ssh/id_ed25519
4
Create a Passphrase (Optional)
Enter a passphrase if you want extra security, or press Enter to skip
5
Start SSH Agent
Type this to start the SSH agent:
eval "$(ssh-agent -s)"
6
Add Key to SSH Agent
Type this to add your key:
ssh-add ~/.ssh/id_ed25519
7
View Your Public Key
Type this to display your public key:
cat ~/.ssh/id_ed25519.pub
Copy the entire output starting with "ssh-ed25519"
8
Add Key to GitHub
1. Go to GitHub Settings → SSH and GPG keys
2. Click "New SSH key"
3. Paste your public key from step 7
4. Click "Add SSH key"
SSH Key Added!

Your Linux system is now connected to GitHub securely! 🔐

✅ Test Your SSH Connection

1
Test Connection (All Operating Systems)
Type this command in your terminal:
ssh -T git@github.com
2
If You See "Hi [username]!"
Congratulations! Your SSH key is working perfectly. You can now use Git with GitHub securely! 🎉
3
If You See an Error
1. Make sure your public key is added to GitHub (double-check the copy-paste)
2. Check that the SSH agent is running
3. Try the commands again from step 5/6
SSH Setup Complete!

You now have secure SSH access to GitHub. No more typing passwords! 🚀🔐

⚡ Git Commands Reference

76
Total Commands
76
Showing
8
Categories

🎓 Beginner's Guide to Git & GitHub

What is Git?

Git is a tool that tracks changes in your code. Think of it like a time machine for your project - you can save snapshots and go back anytime!

📝 Key Concepts

1
Repository (Repo)
A folder that contains all your project files and the entire history of changes. Think of it as your project's memory!
2
Commit
A snapshot of your code at a specific moment. When you make changes and want to save them, you 'commit' with a message explaining what changed.
3
Branch
A separate copy of your code where you can work independently. It's like having multiple versions so you can experiment safely!
4
Pull Request (PR)
A way to ask for your code changes to be reviewed and merged into the main branch. It's how teams collaborate and review code before it goes live!
5
GitHub Actions
Automated workflows that run when you push code or create a PR. Think of it as a robot that tests your code automatically!

🌳 Visual Guide: How Git Actually Works

main branch feature branch ⬤ commit ▲ branch pointer 🎯 HEAD 📄 file 📦 staging
❓ Why Do We Need Version Control?

• No more final_v2_FINAL.py — every change is a tracked snapshot, not a guess
• Undo mistakes safely by reverting to any earlier snapshot
• Multiple people can work on the same project without overwriting each other
• See exactly what changed, when, and who changed it

📝 How Version Control Works

📁
Files on Disk
↓
📝
Working Directory
📄 app.py Clean
↓git add
📦
Staging Area (.git/index)
📄 app.py Empty
↓git commit
🗂
Local Repository (.git)
Previous commits only
↓git push
☁️
Remote Repository (GitHub)
Not pushed yet
Step 1 / 6
💡 Key Idea

Git records snapshots. Files move from Working Directory → Staging Area → Repository — and committing never deletes your working copy, it just saves a snapshot.

🌳 How Git Branching Works

ACommit A — snapshot of: app.py, index.html, README.md BCommit B — snapshot of: app.py, index.html, README.md CCommit C — snapshot of: app.py, index.html, README.md DCommit D — snapshot of: app.py, index.html, README.md, feature.py FCommit F — snapshot of: app.py, index.html, README.md ECommit E — snapshot of: app.py, index.html, README.md, feature.py MMerge commit M — combines main and feature histories main feature 🎯 HEAD
Step 1 / 7
Note: This example creates a merge commit because both branches changed. If only feature had new commits, Git could perform a Fast-Forward merge instead — just moving the main pointer forward, no merge commit needed.
⚠️ What if there's a conflict?

main commit F changes app.py line 10, and feature commit E also changes app.py line 10.

⚠️ Conflict! Both branches modified the same part of the file, so Git needs your help deciding which change to keep.

💡 Key Idea

Branches are lightweight pointers to commits — not copies of your files. Merging combines two lines of history back together.