Back to Blogs
Git

Git for Beginners: Basics and Essential Commands

P
Punyansh Singla
January 10, 20265 min read
GitGit BasicsGit for BeginnersGit for DevelopersVersion ControlGit for Teams

Git Made Simple: A Beginner’s Guide

What is Git?

Git is a tool that helps you track changes in your files, especially code.

Think of Git like a smart save system:

  • Every time you make an important change, you save it using Git.
  • You can go back to any old version anytime.
  • You can work with other people without breaking each other’s work.

Git is a distributed version control system.

This means:

  • Every developer has their own full copy of the project.
  • No single computer controls everything.
  • Everyone can work independently and later share changes.

Why Git is Used

Git is used because it makes work safe and organized.

Main reasons:

  • Track who changed what and when
  • Undo mistakes easily
  • Work with many people on one project
  • Try new ideas without breaking main code
  • Keep full history forever

Without Git:

  • You will make folders like project_final, project_final2, project_final_last

With Git:

  • You save versions properly and can return anytime.

Git Basics and Core Terminologies

Repository (Repo)

A repository is your project folder that Git tracks.

It contains:

  • Your files
  • Hidden Git data
  • Full history of changes

Commit

A commit is a saved version of your project.

It is like taking a photo of your code.

Each commit has:

  • Message
  • Date and time
  • Author
  • Unique ID

Branch

A branch is a separate line of work.

Example:

  • main branch = stable code
  • feature-login = login feature

You can:

  • Work safely
  • Merge later

HEAD

HEAD means:

  • Your current position
  • Which commit or branch you are on

Git Working Areas

Git has three main areas:

  1. Working Directory – where you edit files
  2. Staging Area – where you prepare files
  3. Repository – where commits are stored

Flow

Working Directory → Staging Area → Repository

Git Working Flow

Git Working Flow

Local Repository Structure

A local repo contains:

  • Your files
  • A hidden .git folder
  • All commits and branches

Commit History Flow

Commits form a chain:

Commit A → Commit B → Commit C → Commit D

Each new commit points to the previous one.

Commit History

Commit History

Common Git Commands

git init

Create a new repository.

bash
git init

git status

Check current project state.

bash
git status

git add

Move files to staging area.

bash
git add file.txt
git add .

git commit

Save staged files.

bash
git commit -m "Add login page"

git log

See commit history.

bash
git log

git branch

Show or create branches.

bash
git branch
git branch feature-ui

git checkout

Switch branches.

bash
git checkout feature-ui

git merge

Merge branches.

bash
git merge feature-ui

Basic Developer Workflow Using Git

Step 1: Create Project

bash
mkdir myapp
cd myapp
git init

Step 2: Create Files

Create index.html

html
<h1>Hello World</h1>

Check:

bash
git status

Step 3: Add and Commit

bash
git add .
git commit -m "First version of website"

Step 4: Make Changes

Edit file:

html
<h1>Hello Git</h1>
<p>Learning Git is easy</p>

Save:

bash
git add .
git commit -m "Update homepage text"

Step 5: Create Feature Branch

bash
git branch feature-about
git checkout feature-about

Create about.html

html
<h1>About Us</h1>

Save:

bash
git add .
git commit -m "Add about page"

Step 6: Merge to Main

bash
git checkout main
git merge feature-about

Now your main branch has the new feature.

Simple Git Flow Summary

  1. Edit files
  2. Check: git status
  3. Stage: git add
  4. Save: git commit
  5. Use branches
  6. Merge when ready

Final Thoughts

Git is not scary.

It is just a smart way to save and manage your work.

Remember:

  • Edit
  • Add
  • Commit
  • Branch
  • Merge

Practice a little, and Git becomes your project’s time machine.

Enjoyed this article?

Share it with your network

AI Assistant

Powered by Gemini

Hey there! 👋 I'm Punyansh's AI assistant. Feel free to ask me anything about his skills, projects, or experience!
20 / 20 messages remaining today