Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Published
•6 min read•View as Markdown

Git is a very important tool for developers because it lets us write code without fear. Before we go for the commands, and deepdown in it, let’s know what Git is. and how this solves the dev community pain point

What is git?

Git is a free, open-source, distributed version-control-system in short, VCS. And it is designed to track changes in the project source code during software development. It helps developers manage code efficiently, even in very large projects.

Git in simple words —>

  • A time machine for our code.

  • A safety net that lets us code without any fear.

  • A tracker who tracks the code.

  • Git = CCTV Camera for Your Project

Git is built to be fast and efficient, even for projects with millions of lines of code. That’s one of the reasons it is trusted for large-scale systems like the Linux kernel and is widely used by developers all over the world.

“Do you know this about Git?”

When was Git invented, and who is behind it?

Git was created in 2005 by Linus Torvalds, the creator of Linux.
It was built to handle large projects efficiently while keeping a complete history of changes.

If you want to know why the git is exsit, you can read my previous blog.

Why Version Control Exists: The Pendrive Problem

Are you confused between Git and GitHub?

I am asking this question because when i was started my carrer i feel both are same 😁. And in an interview i got to know that no both are not same. The main difference between the two is that

git —> a tool installed on our system that tracks code changes.

github —> is a cloud platform that hosts git repositories(now you can understand as a project files) and helps teams collaborate online.


Why is Git used?

As humans, everyone makes mistakes — and developers are no exception.

  1. On a daily basis devloper make many changes in the current project, like adding some lines of code and removing some lines of code, and in other day they realize that the code they removed yesterday is important 🤦‍♀️.

  2. Now imagine a real-world project where multiple developers are working at the same time, each on their own branch (don’t worry, we’ll discuss branches later 😉). In such cases, it can quickly become confusing to figure out:

    • Who made which change?

    • When the change was made.

    • Which change introduced a bug 🐛?

This is where Git works like magic ✨.
Git tracks every change made to the code and stores information about what was changed, who changed it, and why. Because of this, team leads or project managers can easily identify the source of an issue and fix it without confusion.


Git Basics and Core Terminologies.

Before we learn the git command i want to give u a short tour of git terminologies. This will help you understand which command is used for what and why we use it.

Git commands can feel confusing at first, but once you know the basic terms, everything starts making sense.
So let’s first understand the language of Git — after that, the commands will feel much easier 😊

Repository (Repo)

A repository is where our project lives.

It contains:

  • Our project files

  • All the changes ever made to them

👉 In simple words:
Repository = Our project source code + full history


Branch

A branch is a safe space to work without disturbing the main code.

Developers use branches to:

  • Add new features

  • Fix bugs

If everything works fine, changes are merged later.

👉 Branch = a safe copy to experiment


Commit

A commit is a saved point of your work.

Whenever you make changes and want Git to remember them, you create a commit.

Developers use commits to:

  • Save progress

  • Track changes

  • Go back if something breaks

👉 Commit = a checkpoint in your project


HEAD

HEAD tells Git where you are right now.

It points to:

  • The current branch

  • The latest commit you are working on

Developers use HEAD to:

  • Know their current position

  • Move between commits or branches

👉 HEAD = your current location in Git


Now that we understand these basic terms, learning Git commands will be much easier, because every command is connected to one of these concepts.

Common Git Commands

git init — Start Git tracking

When you have a new project and want Git to track it, the first command is:

git init

This tells Git:
👉 “Start watching this project.”

After this, your folder becomes a Git repository.


git status — Check what’s happening

Before doing anything, developers often check:

git status

This command tells you:

  • Which files are changed

  • Which files are not tracked

  • What is ready to be committed

Think of it as: “What is the current situation?”


git branch — See where you are working

git branch

This shows:

  • Which branch exists

  • Which branch are you currently working on

👉 It helps you understand where your changes are going.


git add — Select files to save

After making changes, Git does not save them automatically.

You must tell Git which changes are important:

git add .

This puts changes into the staging area.

👉 git add = “These changes should be saved”


git commit — Save the changes

Now you tell Git to permanently remember the changes:

git commit -m "Added login feature"

This creates a commit with a message.

👉 Commit = save point in your project


git log — See the history

To see all past commits:

git log

This shows:

  • Commit history

  • Who made changes

  • When they were made

👉 Like reading the project diary.


git push — Send code to remote

After committing locally, you send your code to GitHub:

git push

Now your changes are visible to your team.

👉 Push = share your work


git pull — Get the latest code from the team

Before starting new work, you should update your code:

git pull

This brings the latest changes from the remote repository.

👉 Pull = sync with the team


git merge — Combine branches

When a feature is ready, it is merged into the main branch:

git merge feature-branch

This combines changes from one branch into another.

👉 Merge = join completed work


git stash — Save work for later

Sometimes you are working but need to switch branches urgently.

git stash

This temporarily saves your changes without committing.

👉 Stash = keep work aside safely


git revert — Undo safely

If a mistake is already committed and pushed:

git revert <commit-id>

This creates a new commit that undoes the mistake.

👉 Revert = safe undo


git reset — Go back (use carefully)

git reset

This moves your project back to a previous state.

⚠️ Use carefully, especially in shared projects.

👉 Reset = rewrite history


Conclusion

Git commands are not random commands.
Each command has its own role, and once you understand which command comes after what, Git starts feeling easy instead of scary.
This flow helps you work confidently without breaking your project 😊

More from this blog

BuildWithSmita

30 posts

A space dedicated to simplifying hard topics. Here, complicated ideas are explained step by step in a clear and approachable way, making learning less overwhelming and more enjoyable.