Getting started with GIT

1. Installation

You only need to install Git once.

  • Windows: Download from GIT and install.

  • Mac:

    brew install git
    
  • Linux (Ubuntu/Debian):

    sudo apt update && sudo apt install git
    
    • ArchLinux
    sudo pacman -Syu && sudo pacman -S git
    

Check if it’s installed:

git --version

2. The Git Workflow (The Big Picture)

Before typing anything, let’s understand how Git thinks.

Every project has:

  1. Working Directory → where you edit files.

  2. Staging Area → a “waiting room” where you prepare files you want to save.

  3. Repository (Repo) → Git’s database where snapshots (commits) are stored.

The basic cycle is:

Edit files → Stage them → Commit them

If you keep this 3-step cycle in mind, Git will never feel scary.


3. Getting Started – Your First Project

Step 1: Tell Git who you are (only once)

git config –global user.name “Your Name” git config –global user.email “your@email.com

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

This info will be attached to your changes.

Step 2: Create a Git repository

A repository = your project folder + Git’s history tracking.

mkdir myproject
cd myproject
git init

You just told Git: “Hey, start tracking this folder.”
[Caution: DO NOT initialize git in your local file system (like home, desktop, etc), always create a new file and then initialize git.]

Step 3: Add a file

echo "Hello Git" > hello.txt

Step 4: Check status

git status

It will say: “Untracked file: hello.txt” → meaning Git sees it but hasn’t saved it yet.

Step 5: Stage the file

git add hello.txt

Now hello.txt is in the staging area.

Step 6: Commit the file

git commit -m "First commit: added hello.txt"

Congratulations You just made your first snapshot!


4. Understanding Key Git Concepts

🔹 Commits = Snapshots

Every commit is like saving a checkpoint in a video game. If something breaks, you can go back.

🔹 Branches = Alternate Timelines

Imagine you want to try a new feature but don’t want to break your main project.
You create a branch:

git branch new-feature
git switch new-feature

Now you’re working in a separate timeline. When ready, you merge it back into main.

🔹 Logs = History Book

See your commits:

git log --oneline

It’s like flipping through a project’s diary.

🔹 Remote Repositories = Cloud Backup

Your local repo is only on your computer. A remote (like GitHub) is a backup + collaboration space.

  • Add a remote:

    git remote add origin https://github.com/user/repo.git
    
  • Upload your work:

    git push origin main
    
  • Download updates from others:

    git pull
    

5. Correct Workflow to Follow (as a beginner)

Here’s a safe and simple workflow you should practice until it becomes second nature:

  1. Start a project:

    git init # or
    git clone <url>
    
  2. Make changes → edit files normally

  3. Check status:

    git status
    
  4. Stage changes:

    git add <file>
    
  5. Commit changes:

    git commit -m "message"
    
  6. Repeat steps 2–5 often

  7. When working with others:

    • Pull updates first:
      git pull
      
    • Make your changes
    • Push them:
      git push
      

Think of it as: Pull → Work → Add → Commit → Push


6. Common Real-Life Examples

  • Accidentally deleted a file?

    git checkout -- file.txt
    
  • Want to see what you changed before committing?

    git diff
    
  • Oops, wrong commit message?

    git commit --amend
    
  • Need to undo last commit (but keep files)?

    git reset --soft HEAD~1
    

7. Limitations

  • Large files (like videos, datasets) → use Git LFS.

  • Merging conflicts can happen → but they’re just Git saying: “I don’t know which version to keep; please decide.”

  • Git feels confusing at first → but with practice, it becomes second nature.


8. FAQ

Q: Is Git the same as GitHub?
No. Git is the tool. GitHub is a website to host Git projects.

Q: Do I need to know all commands?
No. Start with init, status, add, commit, log, push, pull. That’s enough for 80% of real-world use.

Q: Can I break my project using Git?
Not really. Since Git keeps history, you can always roll back.


9. Next Steps

Now that you know the basics:

  • Practice by creating small projects.

  • Use branches for experiments.

  • Try pushing to GitHub and collaborating.

Over time, you’ll naturally pick up advanced features like rebasing, stashing, and cherry-picking.