Skip to main content
Madhukar
All Articles

Git for Beginners: Basics and Essential Commands

August 5, 20265 min read
GitVersion ControlSoftware EngineeringBeginner
Git for Beginners: Basics and Essential Commands

Every developer eventually asks the same question: what happens if I break something and can’t get back to a working version? Before Git, the honest answer was often “hope you kept a backup.” Git exists specifically to make that fear unnecessary — giving every developer a complete, searchable history of every change ever made to a project, and a safe way to experiment without fear of losing anything. This guide covers what Git actually is, why it matters, its core vocabulary, and the essential commands you’ll use in nearly every project.

1. What Is Git

Git is a distributed version control system — a tool that tracks changes to a project’s files over time, letting you save snapshots of your work, go back to any previous snapshot, and collaborate with others without overwriting each other’s changes.

“Distributed” is the key word: every developer working on a project has a full copy of its entire history on their own machine — not just the latest version, but every saved snapshot that’s ever existed. This means you can view history, create branches, and make commits entirely offline, without needing to contact a central server for most day-to-day work.

2. Why Git Is Used

A safety net for your code

Every meaningful change can be saved as a labeled snapshot. If something breaks, you can look back through history and find exactly when — and what — changed, instead of guessing.

Real collaboration without overwriting each other

Multiple developers can work on the same project simultaneously, each with their own copy of the history, and later combine their changes together in a controlled, trackable way.

Freedom to experiment safely

Git’s branches (covered in the next section) let you try out a risky idea in an isolated space, without touching the project’s stable, working version — if the experiment doesn’t work out, you simply discard it.

An honest record of a project’s evolution

Git’s history isn’t just a backup — it’s a searchable record of why changes were made, when, and by whom, which becomes invaluable the moment a project has more than one contributor or lasts longer than a few weeks.

3. Git Basics and Core Terminologies

Repository

A repository (or “repo”) is a project folder that Git is tracking — it contains your actual files, plus a hidden .git folder holding the entire history of every saved change.

Commit

A commit is a saved snapshot of your project at a specific point in time, along with a message describing what changed. Think of commits as save points in a game — each one captures exactly what your project looked like at that moment.

Branch

A branch is an independent line of development — a way to work on something (a new feature, an experiment) without affecting the main, stable version of the project until you’re ready to combine it back in.

HEAD

HEAD simply refers to whichever commit you’re currently looking at — almost always the latest commit on your current branch. Think of it as a bookmark marking “you are here” in the project’s history.

Working Directory, Staging Area, and Repository

Git organizes changes through three distinct areas:

  • Working Directory — your actual files, as you’re currently editing them
  • Staging Area — a holding area where you mark exactly which changes you want included in your next commit
  • Repository — where committed snapshots are permanently stored, as part of the project’s history

This three-stage model is genuinely central to how Git works day-to-day — nearly every basic Git command moves changes from one of these areas to the next.

4. Common Git Commands

Setting up a repository

git init

Turns the current folder into a Git repository, creating the hidden .git folder that will hold its entire history.

Checking what’s changed

git status

Shows which files have been modified, which are staged and ready to commit, and which aren’t being tracked by Git yet — the command you’ll run constantly to orient yourself.

Staging changes

git add filename.txt   # stage one specific file
git add . # stage everything that's changed

Moves changes from the working directory into the staging area — marking them as “ready to be included in the next commit.”

Saving a snapshot

git commit -m "Add user login form"

Saves everything currently in the staging area as a permanent snapshot in the repository, along with a message describing the change.

Viewing history

git log

Shows the full history of commits — who made each change, when, and the message describing it — letting you trace exactly how the project evolved over time.

Working with branches

git branch feature-login     # create a new branch
git checkout feature-login # switch to that branch
git checkout -b feature-login # create and switch in one step

Lets you work on something new in an isolated space, separate from your project’s main branch.

Combining work back together

git merge feature-login

Brings the changes from one branch into another — typically used once a feature branch’s work is finished and ready to join the main branch.

Working with a remote repository

git clone <repository-url>   # copy an existing repository to your machine
git push # send your commits to the remote repository
git pull # fetch and merge the latest changes from the remote

These commands connect your local repository to a shared, remote one (commonly hosted on GitHub, GitLab, or similar), enabling real collaboration with other developers.

A Basic Workflow From Scratch

Putting it all together, a typical first workflow looks like this:

mkdir my-project && cd my-project
git init # start tracking this folder with Git

echo "Hello, Git!" > index.html
git status # see that index.html is untracked

git add index.html # stage the file
git status # see that it's now staged

git commit -m "Add initial index.html" # save the first snapshot

git log # view the commit you just made

From here, every future change follows the same rhythm: edit files, check git status, git add the changes you want, and git commit with a clear message describing what changed.

Final Takeaway

Git’s entire model rests on a simple, repeatable cycle: edit files in your working directory, stage exactly the changes you want with git add, and save them permanently with git commit — building up a searchable, reliable history you can always return to. Branches let you experiment safely; git log lets you understand how a project got to where it is; and push/pull/clone extend that same model to real collaboration with other developers. Everything more advanced in Git is built on top of this same basic rhythm — once it feels natural, the rest of Git becomes far easier to pick up.

Frequently Asked Questions

Do I need to use the staging area every time?

> No — you can skip straight to committing tracked files with git commit -am "message", but the staging area is genuinely useful when you've made several unrelated changes and want to commit them separately, with clear, focused messages.

What’s the difference between git pull and git fetch?

> git fetch downloads the latest changes from a remote repository without merging them into your current work. git pull does both at once — fetching and then merging — which is why git pull is more commonly used in simple, everyday workflows.

Can I undo a commit?

> Yes — Git offers several ways to undo or modify recent commits (like git revert or git reset), though the safest approach depends on whether you've already shared that commit with others, which is a nuanced topic worth learning carefully as you go beyond the basics.

Is Git the same thing as GitHub?

> No — Git is the version control tool itself, running locally on your machine. GitHub (along with GitLab, Bitbucket, and similar services) is a separate, online platform for hosting Git repositories and enabling collaboration — Git works perfectly well without ever using any of them.

Originally published by Mr Madhukar

Read the complete article on Medium with full formatting & reader responses.