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

  1. Go to https://git-scm.com
  2. Click Download for Windows
  3. Run the installer
  4. 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”
  5. 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

CommandPurpose
git logView commit history
git diffSee changes
git branchList branches
git pullFetch + merge
git stashSave work temporarily

Best Practices

✔ Commit often
✔ Write meaningful commit messages
✔ Pull before pushing
✔ Use branches for features
✔ Never commit passwords or secrets

Categories: Tech Post

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *