Skip to main content

Git for Beginners: Basics and Essential Commands

Updated 6 min readMarkdown
Part of seriesNetworking Series
Git for Beginners: Basics and Essential Commands

Modern software development would be chaotic without version control. Tools like Git help developers track changes, collaborate safely, and never lose their work. Platforms like GitHub use Git to enable teams around the world to work on the same project together.

Git was originally created by Linus Torvalds to manage the Linux kernel, and today it is the industry standard version control system.

This guide will teach you Git from a beginner’s perspective, focusing on the most important concepts and essential commands.

Why Git Exists

Imagine you are working on a project:

project/
  app.js

You make changes today.

Tomorrow, you make more changes.

Next week, something breaks.

Now you want the old working version back.

Without Git, this is difficult.

With Git, you can:

• Track every change
• Restore older versions
• See who made changes
• Work safely with teams

Git acts like a time machine for your code.

Core Concept: Git Tracks Snapshots

Git does not track individual edits.

Instead, it saves snapshots of your project over time.

Each snapshot is called a commit.

Think of commits like save points in a game.


Git Workflow Overview

Git works in three main areas:

Essential Git Commands

Let’s go step by step.

  1. git init — Git Initialization

This command initializes Git in your project.

git init

This creates the .git folder.

Now Git can track your project.

Use this when starting a new project.

  1. git status — Check Project State

This shows:

• Changed files
• Staged files
• Untracked files

git status

Example output:

modified: app.js
  1. git add — Stage Changes

This tells Git:

"I want to include this file in the next commit."

git add app.js

Or add all files:

git add .

This moves changes to the staging area.

  1. git commit — Save Snapshot

This permanently saves your changes.

The -m flag stands for message. It lets you add a description to the commit.

git commit -m "Added login feature"

This creates a commit.

Each commit has:

• Unique ID
• Message
• Snapshot of files

  1. git log — View History

Shows all commits.

git log

Example:

commit a1b2c3d4 (HEAD -> master)
Author: Saksham
Date: Thu Feb 12 17:12:22 2026 +0766
Message: Added login feature

This lets you see project history.

  1. git diff — See Exact Changes(Commit difference)

Shows what changed inside files.

git diff

This helps you review changes before committing.

  1. git clone — Download Existing Project

Used to copy a project from GitHub.

git clone https://github.com/user/project.git

This downloads the complete project and history.

  1. git branch — Create Branch

Branches allow safe experimentation.

git branch feature-login

This creates a new branch.

Branches let you work without affecting main code.

  1. git switch — Move Between Branches

Switch to another branch:

git switch feature-login

Now you are working in that branch.

  1. git merge — Combine Branches

Combines one branch into another.

git merge feature-login

This merges feature-login into current branch.

  1. git push — Upload Changes to GitHub

Sends your commits to GitHub.

git push origin main

This uploads your changes to the main branch.

  1. git pull — Download Latest Changes

Gets updates from GitHub.

git pull origin main

This keeps your project updated.

Some editor Commands

  1. mkdir — Create a Folder

Definition:
mkdir stands for make directory. It is used to create a new folder (directory).

Create multiple directories:

mkdir folder1 folder2 folder3

Create nested directories (with -p):

mkdir -p project/src/components

Creates all folders even if they don’t exist.

  1. echo — Add Files

A command which is used to print the text to output tab.

echo is used to display text or write text into a file.

Example:

echo Hello

Output:

Hello

Write text to a file

echo Hello > file.txt

Creates file.txt and writes "Hello".

Append text to a file

echo World >> file.txt

Adds "World" without removing existing content.

Real-Life Analogy: Google Docs Save History

Git works like Google Docs version history.

You can:

• Save versions
• Restore older versions
• See change history

Git provides the same capability for code.

Most Important Beginner Commands Summary

Command

Purpose

git init

Start Git

git status

Check changes

git add

Stage changes

git commit

Save snapshot

git log

View history

git clone

Download project

git branch

Create branch

git switch

Change branch

git merge

Combine branches

git push

Upload changes

git pull

Download changes

git restore

Undo file changes (restores a file to its previous state)

git reset

Unstage or undo commits (command moves files out of staging area)

Why Git Is Essential

Git prevents:

• Losing code
• Overwriting changes
• Collaboration conflicts

Git enables:

• Safe development
• Team collaboration
• Full history tracking

Common Beginners Mistakes

  1. Forgetting to initialize Git

Mistake:

git add .

Error happens because Git is not initialized.

Fix:

git init

Why: Git needs to be initialized before tracking files.

  1. Not using cd to enter the correct folder

Mistake:

Running Git commands in the wrong directory.

Fix:

cd project_folder

Check current location:

pwd
  1. Forgetting to save files before committing

Git only commits saved changes.

Fix:

Save the file first, then:

git add .
git commit -m "message"
  1. Forgetting to use git add

Mistake:

git commit -m "message"

This commits nothing if files are not staged.

Fix:

git add filename
git commit -m "message"
  1. Typing wrong folder name in cd

Mistake:

cd projct

Fix:

Use correct spelling:

cd project

Use:

ls

to see correct folder names.

  1. Creating files in wrong location

Mistake:

echo "Hello" > file.txt

but in wrong directory.

Fix:

Navigate first:

cd project
echo "Hello" > file.txt
  1. Forgetting commit message

Mistake:

git commit

Fix:

git commit -m "Added index.html"
  1. Confusing git add . and git commit

Remember:

  • git add → prepares files

  • git commit → saves snapshot

Basic Git Workflow : Real Example

To avoid this use common workflow

Use these command in the correct project folder.

Step 1: Start project

git init

Step 2: Check status

git status

Step 3: Add files

git add .

Step 4: Commit changes

git commit -m "Initial commit"

Step 5: Upload to GitHub

git push origin main

One-Line Summary

Git is a version control system that tracks changes, saves project history, and enables safe collaboration using simple commands like add, commit, push, and pull.

2 views

No comments yet. Be the first to comment.

More from this blog