Git for Beginners: Basics and Essential Commands 🚀

Published: (January 1, 2026 at 01:44 PM EST)
5 min read
Source: Dev.to

Source: Dev.to

Introduction

If you are starting your journey as a developer, you will hear the word Git everywhere.
Job descriptions mention it, open‑source projects require it, and almost every team uses it daily.

But what exactly is Git? And why is it so important?

This article explains Git from scratch, in simple words, with beginner‑friendly examples and commonly used commands.

Developer working with code


📌 What is Git?

Git is a distributed version control system.

That sounds complex, so let’s simplify it.

👉 Git helps you track changes in your code over time.

It remembers:

  • What changed
  • When it changed
  • Who changed it

…and lets you go back to older versions if something breaks.

Think of Git like a time machine for your code.

Instead of saving files like:

project_v1
project_v2
project_final
project_final_real

Git keeps everything organized and clean.

Git meme about file versions

We’ve all been there! Git saves us from this chaos.


🤔 Why Git is Used

Git solves many real problems developers face.

1️⃣ Track Code History – You can see what changed and why it changed.

2️⃣ Work Without Fear – Made a mistake? You can revert to a previous version easily.

3️⃣ Collaboration – Multiple developers can work on the same project without overwriting each other’s code.

4️⃣ Industry Standard – Almost every company and open‑source project uses Git with platforms like:

  • GitHub
  • GitLab
  • Bitbucket

👉 Learning Git is non‑negotiable for developers.

Team collaboration


🧠 Git Basics and Core Terminologies

Before diving into commands, let’s understand the basic concepts.

📁 Repository (Repo)

A repository is a folder that Git tracks. It contains:

  • Your project files
  • Git’s history and metadata

Create one with:

git init

📦 Commit

A commit is a snapshot of your code at a specific point in time. Think of it as a “save point with a message.”

Each commit has:

  • A unique ID (hash)
  • Author
  • Date
  • Message explaining the change

🌿 Branch

A branch lets you work on features independently.

  • main (or master) → default branch
  • Feature branches → new ideas or fixes

Branches let you experiment without breaking the main code.

📍 HEAD

HEAD points to your current position in Git history. In simple terms: HEAD = “where you are right now.”

Usually, HEAD points to the latest commit of the current branch.


📊 Understanding Git Workflow

Here’s how Git organizes your work:

Git workflow diagram

Three main areas:

  1. Working Directory – Where you make changes.
  2. Staging Area – Where you prepare changes for commit.
  3. Repository – Where Git permanently stores commits.

🗂️ Git Repository Structure

Git repository structure

Your local repository consists of:

  • Working Directory – Your actual project files.
  • .git folder – All Git metadata and history.
  • Remote Repository – GitHub/GitLab (optional).

🛠 Common Git Commands (With Examples)

Let’s learn Git commands by actually using them.

🔹 git init

Initializes Git in your project folder.

git init

Creates a hidden .git folder that Git uses to track everything.

🔹 git status

Shows the current state of your repository.

git status

It tells you:

  • Which files are untracked, modified, or staged.
  • If you have any commits pending to be pushed.

🔹 git add

Stages changes for the next commit.

git add           # stage a specific file
git add .         # stage all changes in the current directory

🔹 git commit

Records a snapshot of the staged changes.

git commit -m "Your descriptive commit message"

🔹 git log

Shows the commit history.

git log

Add --oneline for a compact view:

git log --oneline

🔹 git branch

Lists, creates, or deletes branches.

git branch               # list all local branches
git branch   # create a new branch
git -d           # delete a branch

🔹 git checkout

Switches to another branch or restores files.

git checkout    # switch branches
git checkout       # discard changes in a file

🔹 git merge

Integrates changes from another branch into the current one.

git merge 

🔹 git push

Uploads local commits to a remote repository.

git push origin 

🔹 git pull

Fetches and merges changes from the remote repository.

git pull origin 

🎉 Wrap‑Up

Git is an essential tool for every developer. By mastering the basics—repositories, commits, branches, and the core workflow—you’ll be ready to collaborate efficiently, keep a clean project history, and avoid the pitfalls of “code chaos.”

Start experimenting with the commands above, and soon Git will feel like a natural extension of your development workflow. Happy coding!

Git Basics Cheat‑Sheet


❓ What’s new / modified / staged?

  • New files – files that don’t exist in the repository yet.
  • Modified files – files that have been changed since the last commit.
  • Staged files – files you’ve added to the index (the staging area) and are ready to be committed.

📌 Staging means “I want to include this in the next commit”.


🔹 git add

Add files to the staging area.

# Add a single file
git add filename.txt

# Add everything in the current directory
git add .

🔹 git commit

Create a snapshot of the staged changes.

git commit -m "Add initial project files"

✔️ Best practice: Write clear, meaningful commit messages.

Bad example

git commit -m "changes"

Good example

git commit -m "Add login page UI"

🔹 git log

Show the commit history.

git log

Typical output includes:

  • Commit hash
  • Author
  • Date
  • Commit message

Commit history flow


🔹 git branch

Manage branches.

# List all branches
git branch

# Create a new branch
git branch feature-login

# Switch to a branch (old way)
git checkout feature-login

# Switch to a branch (modern way)
git switch feature-login

🔹 git merge

Combine changes from one branch into another.

git merge feature-login

📌 Merging integrates work from different branches.


🔄 A Simple Git Workflow (From Scratch)

  1. Create a project

    mkdir my-project
    cd my-project
  2. Initialize Git

    git init
  3. Create a file

    touch index.html
  4. Check status

    git status
  5. Stage the file

    git add index.html
  6. Commit changes

    git commit -m "Add initial HTML file"

🎉 Congratulations! You just created your first Git commit.

Success celebration


😄 Git Reality Check

Git commit meme


💡 Tips for Beginners

  • ✅ Run git status often.
  • ✅ Commit small, meaningful changes.
  • ✅ Write clear commit messages.
  • ✅ Don’t fear breaking things—Git has your back.
  • ✅ Practice with small projects.

Learning journey

🎯 Conclusion

Git might seem intimidating at first, but once you understand the basics, it becomes second nature.

Start with these commands, practice regularly, and soon you’ll be managing complex projects with confidence!

What’s your biggest Git challenge? Drop a comment below! 👇

Back to Blog

Related posts

Read more »