✅ Step 1: Setup Git (One-Time)
🔧 If not already installed:
Download Git: [Link]
After installation, configure Git:
git config --global [Link] "Your Name"
git config --global [Link] "your-email@[Link]"
✅ Step 2: Create a Simple Project
📁 Open any folder and create files:
Create a folder called todo-app, and add a simple HTML file:
📝 [Link]
<!DOCTYPE html>
<html>
<head>
<title>To-Do App</title>
</head>
<body>
<h1>My To-Do List</h1>
<ul>
<li>Learn Git</li>
<li>Build a project</li>
<li>Upload to GitHub</li>
</ul>
</body>
</html>
✅ Step 3: Initialize Git Repo Locally
Open terminal in todo-app folder:
git init
✅ Step 4: Add and Commit Your Code
git add .
git commit -m "Initial commit - simple to-do app"
✅ Step 5: Create GitHub Repository and Push Code
1. Go to [Link]
2. Click New Repository
3. Name: todo-app
4. Don’t initialize with README
5. Click Create Repository
Back in terminal:
git remote add origin [Link]
git branch -M main
git push -u origin main
✅ Step 6: Create a Branch
git checkout -b feature/add-css
Now add this file:
📝 [Link]
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
Link it in [Link]:
<link rel="stylesheet" href="[Link]">
git add .
git commit -m "Added CSS styling"
git push -u origin feature/add-css
✅ Step 7: Pull Changes (from GitHub to local)
If someone else made changes:
git pull origin main
✅ Step 8: Fork a Project and Open Pull Request
1. Go to [Link]
2. Search any public repo (e.g., [Link]
3. Click Fork
4. Clone your fork:
git clone [Link]
5. Make changes → push to your fork
6. Click Compare & Pull Request on GitHub
7. Click Create Pull Request
✅ Step 9: Merge vs Rebase
🔁 Merge (default and safe)
Switch to main branch:
git checkout main
git pull
git merge feature/add-css
git push origin main
🔀 Rebase (linear history)
git checkout feature/add-css
git rebase main
✅ Step 10: Squash Commits
Let’s say you have 3 commits on a branch:
git rebase -i HEAD~3
Change first line to pick and others to squash. Save and write a new commit message.
Push using:
git push --force
✅ Step 11: Delete Branches
🔽 Local:
git branch -d feature/add-css
🔼 Remote:
git push origin --delete feature/add-css
✅ Step 12: Undo Commits
Undo last commit but keep changes:
git reset --soft HEAD~1
Undo and remove changes:
git reset --hard HEAD~1