You are in the right place. This guide will make Git feel simple, practical, and approachable.
Hello, Learner! 🙏
If you've heard words like Git, GitHub, commit, branch, merge and felt confused — that's completely normal. Almost every developer feels that way at the beginning.
Here's the good news: Git is not as scary as it looks. Once you understand what it does and why it exists, the commands start making sense naturally.
This guide is written like a patient teacher. No heavy jargon. No rushing. Just clear, friendly explanations with real-life examples.
✅ What This Guide Covers
- What Git and GitHub actually are
- Why Git is used in real projects
- All important terms with simple analogies
- Step-by-step workflows for common tasks
- Most important commands with examples
- Common beginner mistakes to avoid
- 7-day learning plan for real confidence
👥 Who Is This For?
- New developers starting with source control
- Power Platform makers and app builders
- SharePoint and D365 developers
- Solution architects understanding team Git
- Anyone who hears "push the PR" and wants to know what it means
Reassurance: Senior developers with 10+ years of experience also forget Git commands and Google them. That's perfectly normal. The key is understanding the concept, not memorizing every flag.
A simple explanation of the tool that tracks every change you make to your code
Git in One Simple Sentence
Git is a tool that remembers every change you ever make to your files — like a time machine for your code.
When you write code, you're constantly making changes — adding features, fixing bugs, removing old lines. Git keeps a complete history of all those changes so you can go back to any point in time.
🏫 A Real-Life Analogy: The School Notebook
Imagine you're writing a big school project in a notebook.
- Every time you make a major edit, you take a photocopy of the notebook
- You write the date and a note on the copy: "Added introduction chapter — 12 May"
- Later, if your teacher says the old version was better, you can pull out that old photocopy
- You can also share copies with classmates who make their own edits
Git does exactly this — but for code files, automatically, and much smarter.
This is called Version Control. It means tracking versions (snapshots) of your files over time.
🔄 When Something Breaks
You add new code and suddenly the application crashes. With Git, say: "Take me back to yesterday's version" — in one command. No manual undo-ing needed.
👥 Team Collaboration
Two people work on the same project simultaneously without overwriting each other. Git handles the merging intelligently.
🧪 Safe Experimentation
Create a separate branch. Experiment freely. If it goes wrong, delete the branch. Your main code is untouched.
📜 History & Audit Trail
See exactly who changed what and when — invaluable for debugging: "Who changed this line and why?"
The online home for Git repositories — where teams collaborate, review, and share code
GitHub in One Simple Sentence
GitHub is a website where you can store your Git repository online — so your team can access it, collaborate, and review code together.
⛅ Analogy: Google Drive for Code
- You write a document on your laptop → that's your local file
- You save it to Google Drive → now it's online, accessible, and shareable
With code: write it with Git tracking locally → upload to GitHub → team can access, review, and contribute.
💾 Backup
If your laptop breaks, code is safe on GitHub. Just clone it again from anywhere.
🤝 Collaboration
Multiple team members push changes; others pull them. All coordinated through GitHub.
👁️ Code Review
Before code merges, teammates review it via Pull Requests — like a teacher checking homework before submission.
🚀 Deployment
GitHub Actions auto-deploys your app when you push code — like this very portfolio website!
Local Machine vs GitHub
| Your Local Machine | GitHub (Online) |
|---|---|
| Code lives on your computer | Code lives on GitHub's servers |
| Only you can see it by default | You control access (public/private) |
| Works without internet | Requires internet to sync |
| Risky if computer breaks | Safe cloud backup |
| No collaboration features | Central point for team PRs, issues, actions |
GitHub is not the only platform. There's also GitLab, Bitbucket, and Azure DevOps Repos. They all work with Git. GitHub is the most popular one.
They sound similar but are very different things. Here's the definitive comparison.
The Simple Analogy
- Microsoft Word = the tool you use to write and edit a document (on your computer)
- Google Docs = the online platform where you store, share, and collaborate
Similarly: Git = tool on your computer | GitHub = online platform for storing and collaborating on Git repos.
You can use Git without GitHub (work locally). But you can't use GitHub properly without Git — because GitHub hosts Git repositories.
Side-by-Side Comparison
| Git | GitHub |
|---|---|
| A tool (software) | A platform (website/service) |
| Installed on your computer | Runs in the cloud |
| Created by Linus Torvalds (2005) | Founded 2008, acquired by Microsoft 2018 |
| Works completely offline | Requires internet |
| Tracks changes locally | Hosts repos for team access |
| Free and open source | Free for public repos; paid features for teams |
| Interact via terminal commands | Interact via web browser or GitHub Desktop |
9 practical reasons that make Git essential for every developer and team
1. Track Code Changes
Every change is recorded with timestamp and description. Always know what changed, who changed it, and when.
2. Safe Rollback
Spent all day on changes that broke everything? Go back to yesterday's version in one command.
3. Team Collaboration
5 developers, each on their own branch, merging back. Git combines everyone's work intelligently.
4. Safe Experimentation
Create a branch for risky work. Experiment freely. If it fails, delete the branch. Main code is untouched.
5. Code Review via PRs
Before code goes to main, team reviews it via Pull Requests. Catches bugs, maintains quality.
6. Release Management
main for stable production, develop for ongoing work, release/v2.0 for preparing releases. Very organized.
7. Debugging with History
A bug appeared that wasn't there last week? Use git log and git diff to pinpoint exactly which commit introduced it.
8. Parallel Development
5 developers working on 5 features simultaneously using separate branches — no waiting, no interference.
9. Traceability & Audit
Finance, healthcare, and government software need proof of what changed and when. Git provides a complete, tamper-evident trail.
Every Git term explained in plain language with real-life analogies — your Git dictionary
A folder that Git is tracking. Contains all project files plus hidden Git history.
A saved snapshot of your changes, permanently stored in Git history with a message.
A parallel version of your code where you can work without affecting the main code.
Combining changes from one branch into another. Git tries to do this automatically.
Downloading a complete copy of a repository from GitHub — including all history.
Uploading your local commits to GitHub (the remote server).
Downloading the latest changes from GitHub to your local machine.
Downloads updates from remote without merging. Just checks what's new.
The default nickname for your remote repository on GitHub, set automatically when you clone.
Moving to a different branch. git switch branch-name is the modern way.
A proposal on GitHub to merge your branch into another. Others review before approving.
When two people changed the same line of code differently and Git can't decide which to keep.
A preparation area where you select files before committing. Not all changes must go in one commit.
Your actual folder with project files where you make changes. What you see in your file explorer.
A version of your repository that lives online. You push to it and pull from it.
The primary branch — the stable, production-ready version. Modern repos use main.
A file (README.md) explaining what the project is, how to install it, and how to use it.
A file that tells Git which files or folders to not track (passwords, log files, build outputs).
The complete flow from creating a project to sharing it with your team
The Three Stages of Git
| Stage | What It Means | Analogy |
|---|---|---|
| Working Directory | Files you are actively editing | Your open notebook where you write |
| Staging Area | Files selected to commit (prepared) | Items placed in a box, ready to seal |
| Repository (History) | Committed snapshots stored permanently | Sealed & dated box in the archive |
Full Git Workflow — Start to Team Push
- Create a project folder
Start with a regular folder:my-project/ - Initialize Git
cd my-project git init - Create / edit files, then check status
git status - Stage the files
git add . # stage everything git add index.html # or a specific file - Commit the snapshot
git commit -m "Add initial homepage structure" - Connect to GitHub
git remote add origin https://github.com/your-username/my-project.git - Push to GitHub
git push -u origin main - Create a feature branch
git switch -c feature/add-contact-form - Make changes, commit on branch, push
git add . git commit -m "Add contact form with validation" git push origin feature/add-contact-form - Create a Pull Request on GitHub
GitHub → your repo → "Compare & pull request". Team reviews. Once approved, merge!
Install Git and configure it — do this once before your very first commit
Step 1 — Install Git
- Windows: Download from
git-scm.comand run the installer - Mac: Open Terminal → type
git --version→ macOS prompts to install if missing - Linux (Ubuntu):
sudo apt install git
Step 2 — Verify Installation
git --version
# git version 2.43.0 ← means it's installed ✓
Step 3 — Configure Your Identity
Every commit is stamped with this information — your digital signature.
git config --global user.name "Your Full Name"
git config --global user.email "youremail@example.com"
Why --global? This setting applies to all Git projects on your computer. You only need to do this once.
Step 4 — Verify & Set Default Branch
git config --list # see all settings
git config --global init.defaultBranch main # use 'main' as default
Step 5 — Set Up SSH Key (Recommended)
SSH keys let you push/pull without entering your password every time.
# Generate SSH key (press Enter for defaults)
ssh-keygen -t ed25519 -C "youremail@example.com"
# Copy the public key
cat ~/.ssh/id_ed25519.pub
Then: GitHub → Settings → SSH keys → Add new key → Paste the key.
Every essential command — click to expand for full details, when to use, and real examples
Click any command to expand its full explanation. In daily work, you'll use 8–10 of these regularly. The rest you look up as needed.
What it does: Prints the installed Git version.
git --version
# Output: git version 2.43.0
What it does: Sets your name, email, and other Git preferences. Run once during setup.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --list # see all settings
What it does: Turns a normal folder into a Git-tracked repository. Creates a hidden .git folder.
mkdir my-project
cd my-project
git init
# Initialized empty Git repository in .../my-project/.git/
What it does: Downloads a full copy of a remote repository — all files and complete history.
git clone https://github.com/username/project-name.git
# Creates a folder called "project-name" in your current directory
What it does: Shows which files are modified, staged, or untracked. Your constant health check.
git status
# On branch main
# Changes not staged for commit:
# modified: index.html
# Untracked files:
# style.css
What it does: Moves files from the working directory into the staging area. Run before git commit.
git add index.html # add a specific file
git add . # add ALL changed files
git add assets/css/ # add an entire folder
What it does: Creates a permanent snapshot in Git history. Commit frequently — every logical unit of work.
git commit -m "Add navigation menu to header"
# Good: "Fix login bug when email has uppercase letters"
# Bad: "changes" or "fixed stuff"
git log
git log --oneline # compact one-line view
git log --oneline --graph # with branch visualization
git diff # changes in working directory
git diff --staged # changes that are staged
git diff main feature/nav # diff between two branches
git branch # list all local branches
git branch -a # list local + remote branches
git branch feature/login # create a new branch
git branch -d feature/login # delete a branch (safe)
git switch main # go to main branch
git switch feature/login # go to existing branch
git switch -c feature/signup # create AND switch to new branch
Older multi-purpose command — still widely used and valid.
git checkout main # switch branch
git checkout -b feature/nav # create and switch
git checkout -- index.html # restore file from last commit
Use git switch for branches and git restore for files — cleaner and less confusing.
git switch main
git merge feature/login # merge feature into main
When to use: Every morning before you start work. Always pull before pushing.
git pull # pull from default remote/branch
git pull origin main # explicitly pull main from origin
git push # push current branch
git push origin main # push main to origin
git push origin feature/login # push a feature branch
git push -u origin main # push AND set upstream (first time)
git fetch origin
git log origin/main --oneline # see what's new remotely
git remote -v # see all remote connections
git remote add origin https://github.com/user/repo.git
git remote remove origin # remove a remote
Use when an urgent bug comes in while you're mid-feature. Stash, fix the bug, then pop your stash back.
git stash # stash all current changes
git stash pop # restore the most recent stash
git stash list # see all stashes
git reset --hard permanently deletes changes. Not recommended for beginners on shared branches.
git reset HEAD index.html # unstage a file (keep changes)
git reset --soft HEAD~1 # undo last commit, keep staged
git reset --mixed HEAD~1 # undo last commit, keep files
Creates a new commit that undoes changes from a previous commit. History is preserved. Beginner-safe on shared branches.
git log --oneline
# abc123 Add broken feature
git revert abc123 # creates a new "undo" commit
Complete command sequences for the 6 most common real-world Git situations
You want to start a new project and track it with Git from the beginning.
# 1. Create the project folder
mkdir my-portfolio && cd my-portfolio
# 2. Initialize Git
git init
# 3. Create first file, stage and commit
echo "# My Portfolio" > README.md
git add .
git commit -m "Initial project setup with README"
# 4. Connect to GitHub (create repo on github.com first)
git remote add origin https://github.com/your-username/my-portfolio.git
git push -u origin main
Your team has an existing project on GitHub and you need to work on it.
git clone https://github.com/team/project-name.git
cd project-name
git branch -a
git switch -c feature/my-changes
git status
git diff
git add index.html
git commit -m "Update header navigation links"
git push
# Get latest main
git switch main && git pull origin main
# Create feature branch
git switch -c feature/user-login
# Work... then commit and push
git add .
git commit -m "Add user login form and validation"
git push origin feature/user-login
# On GitHub → create Pull Request → team reviews → merge
git switch main
git pull origin main
# Update your feature branch too
git switch feature/my-feature
git merge main # bring main's updates into your branch
# Option 1: Undo last commit but keep files
git reset --soft HEAD~1
# Option 2: Safely revert a specific commit (recommended)
git log --oneline
git revert abc1234
# Option 3: Restore a single file to last commit
git restore index.html
Always use git revert for undoing on shared/team branches. Safe, doesn't rewrite history.
Build healthy Git habits — a simple daily routine that keeps you and your team happy
🌝 Morning — Start of Day
- Pull latest:
git switch main && git pull origin main - Create/switch to your branch:
git switch -c feature/todays-task - Check state:
git status(should be clean)
💻 During Work
- Commit small & often:
git add . && git commit -m "..." - Check often:
git statusandgit diff - Urgent work?
git stash→ fix →git stash pop
🌆 End of Day
- Commit all finished work with a clear message
- Push branch to GitHub:
git push origin feature/... - Create a PR on GitHub if feature is complete
Golden Rules: Pull before you push. Commit often, commit small. Write meaningful messages. Never work directly on main. Push before end of day — it's your backup.
How experienced professionals use Git differently — strategy, oversight, and governance
👁️ Reviewing Pull Requests
git fetch origin
git switch feature/dev-login
# test it, then:
git switch main
📜 Understanding History
git log --oneline --graph --all
git log --author="Dev Name"
git blame src/auth/login.js
🚺 Release Management
git switch -c release/v2.1.0 develop
git switch main
git merge release/v2.1.0
git tag v2.1.0
git push origin main --tags
🛡️ Branch Strategy & Governance
- Set branch protection rules (require PR reviews)
- Enforce commit message conventions
- GitHub Actions for CI/CD auto-testing on every PR
- Monitor stale branches and open PRs
Branch Strategy Reference
| Branch | Purpose | Who Merges |
|---|---|---|
main | Production-ready code only | Architect / Lead |
develop | Integration branch for ongoing work | Lead Developer |
feature/* | Individual feature work | Developers via PR |
release/* | Preparing for release | Release Manager |
hotfix/* | Emergency production fixes | Architect |
Learn from others — avoid these 8 pitfalls before they bite you
❌ Committing Directly to Main
Making all changes on main instead of creating a feature branch. Fix: git switch -c feature/my-task — always, no matter how small the task.
❌ Forgetting to Pull Before Starting Work
Your code becomes outdated. Fix: Make git pull the very first command every morning, before writing a single line.
❌ Vague or Bad Commit Messages
# ❌ Bad git commit -m "changes"
# ✓ Good git commit -m "Fix mobile login button not responding on iOS 17"
❌ Committing Passwords or API Keys
Once pushed to a public repo, secrets are exposed forever — even if deleted later (they're still in history). Fix: Add .env to .gitignore before your first commit.
❌ Panicking During a Merge Conflict
Conflicts are normal. They're just Git asking which version of a line to keep. Open the file, pick the right version, remove the markers, commit. See Section 14.
❌ Forgetting .gitignore
# Example .gitignore
node_modules/
.env
dist/
*.log
.DS_Store
Use gitignore.io to generate one for your tech stack.
❌ Pushing Unfinished Work to Main
Always push to a feature branch. Only merge to main via Pull Request after testing and review.
❌ Confusing Git and GitHub
Git = tool on your machine. GitHub = website for hosting. You can commit locally without internet. Internet is only needed when pushing or pulling from GitHub.
They look scary. They're actually just Git asking you a question.
What Is a Merge Conflict?
A merge conflict happens when two different people edited the same line in the same file and Git can't decide which version to keep. Git is smart enough to merge most changes automatically. When it literally cannot decide, it stops and asks YOU.
What Does a Conflict Look Like?
<<<<<<< HEAD
<h1>Welcome to My Portfolio</h1>
=======
<h1>Hello, I'm a Developer!</h1>
>>>>>>> feature/new-hero-text
<<<<<<< HEAD→ Your current branch's version=======→ Divider between the two versions>>>>>>>→ The incoming branch's version
How to Resolve — Step by Step
- Don't panic. Open the conflicting file.
- Read both versions. Decide which is correct (or combine them).
- Delete the conflict markers and leave only the correct code.
- Save the file.
git add index.html git commit -m "Resolve merge conflict in hero heading"
VS Code
Shows conflicts with "Accept Current", "Accept Incoming", "Accept Both" buttons — no manual marker removal needed.
GitHub Web Editor
Can resolve simple conflicts directly in the browser during a Pull Request.
Best Prevention: Pull before you push, merge main into your branch regularly, and keep branches short-lived. The longer a branch lives, the more conflicts accumulate.
Simple habits that make you a professional Git user from day one
✅ Commit Often, Commit Small
Small commits = easy history, easy bug-finding, easy to revert. Don't wait until you've written 500 lines.
✅ Write Meaningful Commit Messages
Format: verb + what + context. "Fix calculation bug in invoice total" beats "changes" every time.
✅ Always Use Branches
Main should always be deployable. Never work directly on it. One branch per feature or bug fix.
✅ Pull Before You Push
Always pull the latest before pushing yours. Prevents conflicts and protects others' work.
✅ Never Commit Secrets
Always put .env in .gitignore. Once a secret is in history, it's considered compromised.
✅ Write a README
Explain: what it does, how to set it up, how to run it. Future you will thank present you.
✅ Set Up .gitignore at Start
Before your first commit. Use gitignore.io to generate the right entries.
✅ Keep Branches Short-Lived
The longer a branch lives without merging, the more conflicts accumulate. Break large features into smaller PRs.
✅ Use git revert on Shared Branches
Never use git reset --hard on shared branches. Use git revert — safe, preserves history.
✅ Use Git History as a Superpower
git log, git diff, git blame. When something breaks, they help pinpoint exactly what changed.
Honest answers to the questions every beginner is afraid to ask
Git feels difficult at first because many commands are introduced all at once. But in daily work you use only 8–10 commands repeatedly. Once those become habit (usually 2–3 weeks), Git feels automatic. The hardest part is the first 3 days.
No! Git works completely offline. You can create repos, commit, branch, and merge entirely locally. GitHub is only needed when you want to share code with others, back it up online, or collaborate as a team.
Yes! This is one of Git's biggest strengths. Use git revert to safely undo commits. Use git reset to unstage files. Use git restore to discard working directory changes. The only hard-to-undo situation is git reset --hard after you've lost uncommitted work — which is why committing frequently matters.
Not pushed yet: git reset --soft HEAD~1 undoes the commit but keeps your files. Already pushed: git revert [commit-id] creates a new commit that reverses the changes. Never use git push --force on a shared branch.
Deleted and not committed yet: git restore deleted-file.js brings it back instantly. Already committed the deletion: git revert [commit-id] will bring the file back. Git almost never truly loses your data if you've been committing regularly.
Branches let you work on new things without risking your stable code. Think of them as parallel universes. If an experiment works, you merge it. If it fails, delete the branch — nothing is lost. In teams, branches allow multiple developers to work simultaneously without interfering with each other.
Not at all! Merge conflicts are completely normal. It's just Git saying "two people changed the same line — please tell me which version to keep." Open the file, pick the right version, delete the conflict markers, save, stage, and commit. See Section 14 for the full walkthrough.
1. Pull from main every morning. 2. Create a new branch for each task. 3. Commit often with clear messages. 4. Push your branch at end of day. 5. Create a PR when done. 6. Never use --force. 7. Use git revert for undoing, not git reset --hard.
One week from zero to confident — a practical daily plan for beginners
How to Follow This Plan: Spend 30–60 minutes each day. Actually type the commands — don't just read. Create a practice folder on your computer. By Day 7 you'll be doing real Git workflows confidently.
🧠 Understand the Concepts
- Read Sections 1–4 of this guide
- Understand Git vs GitHub
- Read Section 6 — all key terms
- No commands yet — just read and understand
⚙️ Setup Git
- Install Git on your computer
- Run
git --version - Configure name and email
- Create a GitHub account (free)
📦 Init, Add, Commit
- Create a practice folder
- Run
git init - Create 2–3 files
- Practice
git addandgit commit - Make 5 commits today
🌐 GitHub Push & Pull
- Create a repo on GitHub
- Connect with
git remote add - Push your Day 3 commits
- Edit a file on GitHub.com
- Pull changes to your local machine
🌿 Branching
- Create a new branch
feature/test - Make changes and commit on the branch
- Switch back to main
- Observe main is unchanged
- Push the branch to GitHub
🔀 Merge & Conflicts
- Merge your feature branch into main
- Intentionally create a conflict
- Resolve it in VS Code
- Commit the resolved conflict
🎯 Real Project Workflow
- Start a mini real project
- Follow Section 11 — Daily Workflow
- Create a PR on GitHub and merge it
- Practice
git stash - Review your full commit history
After 7 Days: Weeks 2–3 — use Git for every project. Month 2 — interactive rebase, cherry-pick. Month 3 — CI/CD with GitHub Actions, branch protection, full PR workflows.
Everything you need to remember, in one place. You're ready.
🏁 Quick Recap
- Git = tool on your computer that tracks code changes over time (offline, local)
- GitHub = website that hosts Git repos for team collaboration (online)
- Commit = a saved snapshot of your changes with a message
- Branch = a parallel version of your code for safe experimentation
- Pull Request = proposal to merge your branch, reviewed by team on GitHub
- Core Flow: Edit →
git add→git commit→git push
⚡ If You Remember Only These 10 Commands...
📋 Full Mini Cheat Sheet
| Command | What It Does |
|---|---|
git init | Initialize new repo |
git clone <url> | Download repo from GitHub |
git status | See changed / staged / untracked files |
git add . | Stage all changes |
git commit -m "msg" | Commit with message |
git log --oneline | View compact history |
git diff | See exact line changes |
git push | Upload to GitHub |
git pull | Download from GitHub |
git branch | List branches |
git switch -c <name> | Create + switch to new branch |
git switch <name> | Switch to existing branch |
git merge <branch> | Merge branch into current |
git stash | Temporarily save work |
git stash pop | Restore stashed work |
git revert <id> | Safely undo a commit |
git remote -v | Show remote connections |
git remote add origin <url> | Connect to GitHub remote |
🏋️ Practice Exercise — Do This Right Now
# 1. Create a practice project
mkdir git-practice && cd git-practice && git init
# 2. Create and commit 3 files
echo "Hello World" > hello.txt
git add hello.txt && git commit -m "Add hello.txt"
echo "Notes here" > notes.txt
git add notes.txt && git commit -m "Add notes.txt"
echo "# My Practice Project" > README.md
git add README.md && git commit -m "Add README"
# 3. Create a branch and add a file
git switch -c feature/add-about
echo "About me: I'm learning Git!" > about.txt
git add about.txt && git commit -m "Add about page content"
# 4. Merge back to main
git switch main && git merge feature/add-about
# 5. View your history
git log --oneline
# 🎉 Congratulations — you just completed a real Git workflow!
📚 Recommended Next Steps
- learngitbranching.js.org — interactive visual Git learning (highly recommended)
- ohshitgit.com — practical fixes for common Git mistakes
- gitignore.io — generate .gitignore for any tech stack
- GitHub Getting Started Docs
Final Words: Git becomes natural with repetition. Every professional developer felt confused at first. Start using Git today for every project, no matter how small. Within a month it will feel like breathing. You've got this! 💪