Git and GitHub Tutorial: Complete Version Control Guide for Developers 2026
Git and GitHub developer ke essential tools hain. Yeh complete tutorial aapko version control ki fundamentals se lekar team collaboration tak sab kuch practical examples ke saath batayega.
Git Kya Hai
Git ek distributed version control system hai jo aapko code ki har change ka track rakhne, branches manage karne, aur team ke saath collaborate karne ki facility deta hai.
Git ke benefits:
- Every change ka record
- Easy rollback to previous versions
- Parallel development with branches
- Safe team collaboration
- Complete project history offline bhi accessible
Git Installation aur Setup
Installation
Linux (Ubuntu/Debian):
sudo apt update
sudo apt install git
macOS:
brew install git
Windows - Download from https://git-scm.com
Initial Configuration
Your identity - yeh har commit mein use hoga:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Default branch name:
git config --global init.defaultBranch main
Enable helpful features:
git config --global init.defaultBranch main
git config --global pull.rebase false
git config --global core.editor code
Check your settings:
git config --list
Git Basic Commands Tutorial
Repository Setup
New repository initialize karein:
git init
Existing remote repository clone karein:
git clone https://github.com/username/repository.git
git clone https://github.com/username/repository.git my-folder-name
Clone specific branch:
git clone --branch branch-name https://github.com/username/repository.git
Git Status aur File Staging
Working directory ki status dekho:
git status
Short status (compact view):
git status -s
Changes ko staging area mein add karein:
git add filename.txt
git add file1.js file2.js
git add src/
All changes stage karein:
git add .
Unstage karna:
git reset HEAD filename.txt
git restore --staged filename.txt
Git Commit Tutorial
Staged changes ko commit karein:
git commit -m "Add user authentication feature"
Add and commit in one step (only tracked files):
git commit -am "Fix login bug"
Commit message best practices:
- First line: Short summary (under 50 chars)
- Blank line
- Detailed explanation (if needed)
Last commit amend karein (message ya files):
git commit --amend -m "Updated commit message"
git commit --amend --no-edit (Same message, new files add)
Git History aur Diff
Commit history dekho:
git log
git log --oneline (Compact view)
git log --graph --oneline --all (Branch visualization)
git log -n 5 (Last 5 commits)
git log --author="Name" (Filter by author)
git log --since="2024-01-01" (Filter by date)
Changes dekho:
git diff (Unstaged changes)
git diff --staged (Staged changes)
git diff HEAD~3 HEAD (Last 3 commits changes)
git diff main feature-branch (Compare branches)
Specific file ka diff:
git diff filename.txt
git diff --staged filename.txt
Git Branching Tutorial
Branching aapko code ki separate copies par kaam karne ki facility deta hai bina main code ko affect kiye.
Branch Basics
Branch list dekho:
git branch
All branches dekho (local + remote):
git branch -a
New branch banao:
git branch feature-login
Branch mein switch karein:
git checkout feature-login
git switch feature-login (New command)
New branch banao aur switch karein:
git checkout -b feature-dashboard
git switch -c feature-dashboard (New command)
Remote branch se track karein:
git checkout --track origin/feature-xyz
Branch Management
Branch ko rename karein:
git branch -m old-name new-name
Branch delete karein:
git branch -d feature-old (Safe delete - merged)
git branch -D feature-old (Force delete - unmerged)
Remote se branch delete karein:
git push origin --delete feature-old
Git Merge Tutorial
feature branch ko main mein merge karein:
git checkout main
git pull origin main
git merge feature-login
Merge types:
- Fast-forward: Direct linear progression
- Three-way merge: Creates merge commit
Merge conflict solve karna:
- Conflict markers dekho
- File edit karein
- git add filename.txt
- git commit
Git Rebase Tutorial
Rebase - commit history clean rakhne ke liye:
git checkout feature-login
git rebase main
Interactive rebase - commit history edit karne ke liye:
git rebase -i HEAD~3 (Last 3 commits)
Rebase commands: pick, squash, drop, etc.
Warning: Public commits mat rebases karna
GitHub Tutorial: Remote Collaboration
GitHub Git repositories host karne ka platform hai. Yeh team collaboration, code review, aur continuous integration ke liye use hota hai.
Git Remote Setup
Remote add karein:
git remote add origin https://github.com/username/repo.git
Remote URLs dekho:
git remote -v
Remote URL change karein:
git remote set-url origin https://github.com/username/repo.git
Multiple remotes:
git remote add upstream https://github.com/original-owner/repo.git
Git Push aur Pull
Local commits ko remote par push karein:
git push origin main
git push -u origin feature-branch (Track for future)
All branches push karein:
git push --all origin
Tags push karein:
git push origin v1.0.0
git push origin --tags
Remote changes pull karein:
git pull origin main
git pull --rebase origin main (With rebase)
Fetch (download without merge):
git fetch origin
git fetch --all
GitHub Workflow Tutorial
Feature Branch Workflow
- Main branch se naya feature branch banao:
git checkout main
git pull origin main
git checkout -b feature-user-auth
- Code likho aur commits karo:
git add .
git commit -m "Add login form component"
git commit -m "Implement authentication logic"
git commit -m "Add unit tests for auth"
- Main branch latest karo:
git checkout main
git pull origin main
git checkout feature-user-auth
git merge main (Resolve conflicts if any)
- GitHub par push karo:
git push -u origin feature-user-auth
Pull Request Tutorial
- GitHub repository mein jaao
- "New Pull Request" button click karo
- Base branch (main) aur compare branch (feature-user-auth) select karo
- Pull request title aur description likho
- Reviewers assign karo
- Create Pull Request click karo
Git Cheat Sheet
Quick commands:
git init (New repo)
git clone url (Copy repo)
git add . (Stage all)
git commit -m "msg" (Commit)
git push (Upload)
git pull (Download)
git status (Check status)
git log --oneline (History)
git branch (List branches)
git checkout -b new (Create + switch)
git merge branch (Merge)
git stash (Save work)
git stash pop (Restore work)
Undo mistakes:
git checkout -- file (Discard changes)
git reset HEAD file (Unstage)
git reset --soft HEAD~1 (Keep changes)
git reset --hard HEAD~1 (Delete changes)
git revert HEAD (New commit undoing)
Git Flow Best Practices
- Commit small, logical units
- Write clear commit messages
- Pull before you push
- Never commit secrets to repo
- Use branches for features
- Review code before merging
- Delete merged branches
- Keep main/main clean
Cyber Defence Git/GitHub Course
Cyber Defence mein Git and GitHub ka complete training available hai jo version control fundamentals se lekar team collaboration tak cover karta hai. Hands-on exercises ke saath real-world workflows practice karte hain students.
FAQs
Git aur GitHub mein kya farak hai?
Git version control software hai jo locally install hota hai. GitHub is a cloud platform jo Git repositories host karta hai. Similar platforms: GitLab, Bitbucket.
Kya GitHub free hai?
Haan, public repositories free hain. Private repositories free plan mein limited features ke saath available hain.
Version control kyun zaroori hai?
Code history track karne, team collaboration, rollback capability, aur parallel development ke liye zaroori hai.
Git learn karne mein kitna time lagta hai?
Basic commands 1-2 din mein seekh sakte ho. Advanced features (branching, merge conflicts) ke liye 2-3 weeks practice chahiye.

