Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Published
3 min read

What is Git?

Git is a distributed version control system.

In simple words:

  • It helps you track changes in your code

  • Lets you go back in time if something breaks

  • Makes collaboration easy with other developers

Every developer has a full copy of the project and its history on their own machine.


Why is Git Used?

Git solves very real developer problems:

  • ✅ Keeps history of every change

  • ✅ Helps undo mistakes safely

  • ✅ Allows multiple people to work together

  • ✅ Tracks who changed what and why

  • ✅ Makes experimentation safe using branches

Without Git → chaos
With Git → control 😄


Git Basics & Core Terminologies

Let’s break the scary words into simple ideas.

Repository (Repo)

A repository is a folder tracked by Git.
It contains:

  • Your project files

  • Git’s history and metadata


Commit

A commit is a snapshot of your project at a moment in time.

Think of it like:

“Save point in a game 🎮”

Each commit has:

  • A unique ID

  • A message describing the change


Branch

A branch is an independent line of development.

  • main → stable code

  • other branches → experiments, features, fixes

Branches let you work without breaking the main code.


HEAD

HEAD points to:

  • Your current branch

  • Your latest commit

It tells Git: “This is where I am right now.”


Git Workflow (Big Picture)

This is how Git actually works behind the scenes:

https://miro.medium.com/1%2AdiRLm1S5hkVoh5qeArND0Q.png

https://miro.medium.com/v2/resize%3Afit%3A1400/0%2AGalnq-iwwHHWYzmN.png

Three Areas:

  1. Working Directory → where you edit files

  2. Staging Area → files ready to be committed

  3. Repository → saved history (commits)


Common Git Commands (You’ll Use These Daily)

Initialize a Repository

git init

Creates a new Git repository in the current folder.


Check Repository Status

git status

Shows:

  • Modified files

  • Staged files

  • Untracked files


Add Files to Staging Area

git add filename

or add everything:

git add .

Commit Changes

git commit -m "Initial project setup"

Saves changes permanently to history.


View Commit History

git log

Shows:

  • Commit IDs

  • Author

  • Date

  • Commit messages

https://user-images.githubusercontent.com/44003176/103466403-36a81780-4d45-11eb-90cc-167d210d7a52.png

https://i.sstatic.net/Zmfuc.gif


Basic Developer Workflow (From Scratch)

Here’s how a beginner actually uses Git 👇

  1. Create a project folder

  2. Initialize Git

     git init
    
  3. Create or edit files

  4. Check status

     git status
    
  5. Stage changes

     git add .
    
  6. Commit changes

     git commit -m "Add initial files"
    
  7. Repeat steps 3–6 as you build features


Local Repository Structure (Conceptual)

https://humbletoolsmith.com/img/posts/a-look-inside-the-_git-folder/Git%20Folder%20Internals.png

https://practicalseries.com/1002-vcs/01-pages/02-02-concept/02-images/fig-02-01.svg

  • .git/ → Git’s brain 🧠

  • Contains commits, branches, logs, and history

  • Never edit .git manually

More from this blog

C

CHAIAURCODE-->WEBCOHORT

13 posts