quick, practical Git basics tutorial — ideal if you just want to start working productively right away.


🧩 1. What Git Is

Git is a version control system — it tracks changes in code so you can:

  • Revert to previous versions
  • Work in parallel (branches)
  • Collaborate safely

⚙️ 2. Initial Setup

Run these once on a new machine:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

You can check settings with:

git config --list

📁 3. Starting a Repo

Create a new repo

git init

Or clone an existing one

git clone https://github.com/user/repo.git

✍️ 4. Making Changes

Stage and commit your work:

git add .           # Add all changed files
git commit -m "Describe what you changed"

View your changes:

git status          # See modified/untracked files
git diff            # Show unstaged changes

🌿 5. Branching & Merging

Create and switch branches:

git branch feature-x       # Create branch
git checkout feature-x     # Switch to it
# or shortcut:
git switch -c feature-x

Merge changes into main:

git checkout main
git merge feature-x

Delete branch after merge:

git branch -d feature-x

☁️ 6. Working with Remote

Push your work:

git push origin main

Pull latest updates:

git pull origin main

Add remote manually:

git remote add origin https://github.com/user/repo.git

🕰️ 7. Undoing Mistakes

Undo last commit but keep changes:

git reset --soft HEAD~1

Discard all uncommitted changes:

git checkout -- .

Revert a specific commit:

git revert <commit-hash>

🔍 8. Inspecting History

git log --oneline --graph --decorate

See who changed what:

git blame file.txt

🚀 Quick Workflow Summary

  1. git pull – update local copy
  2. git switch -c feature-branch – create new branch
  3. edit files
  4. git add .
  5. git commit -m "message"
  6. git push origin feature-branch
  7. open pull request / merge