Below is a clear, beginner-friendly, step-by-step guide to using Git on Windows. No prior Git knowledge assumed.
Git on Windows – Step-by-Step Guide
Install Git on Windows
- Go to https://git-scm.com
- Click Download for Windows
- Run the installer
- During installation:
- Keep default settings (recommended)
- When asked for terminal, choose Git Bash
- Choose “Use Git from the command line and also from 3rd-party software”
- Finish installation
Verify installation:
git --version
If you see a version number, Git is installed.
Open Git Bash
- Right-click anywhere → Git Bash
- Or search Git Bash in Start Menu
Git Bash is the terminal where you’ll run Git commands.
Configure Git (One-Time Setup)
Set your name and email (used for commits):
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
Check settings:
git config --list
Create or Initialize a Git Repository
Option A: Initialize Git in an existing folder
cd /c/Users/YourName/Desktop/my-project
git init
Option B: Clone an existing repository
git clone https://github.com/username/repository.git
Check Repository Status
git status
Shows:
- Untracked files
- Modified files
- Staged files
Add Files to Git
Add a single file
git add filename.txt
Add all files
git add .
Commit Changes
Save changes to Git history:
git commit -m "Initial commit"
📌 Every commit should have a clear message.
Connect to GitHub (Remote Repository)
Add remote origin
git remote add origin https://github.com/username/repository.git
Verify:
git remote -v
Push Code to GitHub
First push
git push -u origin main
(Use master if your branch is named master)
🔁 10️⃣ Daily Git Workflow
git status # Check changes
git add . # Stage changes
git commit -m "Update feature"
git pull # Get latest changes
git push # Upload changes
11️⃣ Branching Basics
Create a new branch
git branch feature-branch
Switch to branch
git checkout feature-branch
Create & switch in one command
git checkout -b feature-branch
12️⃣ Merge Branches
git checkout main
git merge feature-branch
13️⃣ Undo Mistakes
Undo staged file
git reset filename.txt
Undo last commit (keep changes)
git reset --soft HEAD~1
Discard file changes
git checkout -- filename.txt
14️⃣ Useful Git Commands Cheat Sheet
| Command | Purpose |
|---|---|
git log | View commit history |
git diff | See changes |
git branch | List branches |
git pull | Fetch + merge |
git stash | Save work temporarily |
Best Practices
✔ Commit often
✔ Write meaningful commit messages
✔ Pull before pushing
✔ Use branches for features
✔ Never commit passwords or secrets
0 Comments