Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Published
9 min read
Git for Beginners: Basics and Essential Commands

What is Git ?

Git is a distributed version control system that helps developers track changes in their code over time. It allows you to save different versions of your project, collaborate with others, and safely experiment without breaking the main codebase.

So, What is Git is simple words

Okay, imagine you’re working on a project and you keep saving files like
project_final.zip, project_final_final.zip, project_final_real_final.zip
We’ve all been there.

That’s where Git comes in.

Git is basically a smart system that keeps track of all your code changes so you don’t have to worry about messing things up.

Git is like your code memory: With the help of the git you can keep the record and history of the your code Record like :

  1. What you add in the code.

  2. What you remove from the code.

  3. What changes did you make in the code.

Git is like made a mistake?
No worries — Git’s got your back

This is the main website of the GIT

https://git-scm.com/

This is link of the Git website https://git-scm.com/

Why Git is Used

The main purpose of the git is to keep the records and history of the code. Git keeps a complete history of your project. we use Git to save our work safely and track changes in our code.

Think of Git like a save button with memory
It remembers every change you make, so you can:

  1. Go back if something breaks.

  2. See what you changed earlier in code.

  3. Work without fear of losing code.

Why We Use Git (In Simple Words)

In Git, we create checkpoints at different stages of our code.
Whenever our code is working properly, we save that moment as a checkpoint (called a commit).

If later something goes wrong or an error appears, we can easily go back to the previous checkpoint and continue working from there. This helps us avoid losing progress and keeps our code safe.

Git allows us to move back and forth between different versions of our project.
You can think of it like a time machine for your code

Git helps manage the history of your code and allows you to merge changes from different branches smoothly.
So instead of creating many copies of files, Git keeps everything organized in one place.

Working of the Git

Git is a version control system, which means it keeps track of every change you make to your project. Think of it like a diary for your code that also lets you travel back in time whenever you need.

Git Basics and Core Terminologies

Git is a tool that helps developers manage their code easily.
It is mainly used to track changes and save the history of a project.

When you write code, mistakes can happen.
Sometimes new changes break old working features.
Git helps you go back to a safe point without losing your work.

Before Git, developers used to save files like:

  1. Project_Final_v1

  2. Project_Final_v2

  3. Project_Final_real_v3

  4. Project_Final_last_v4

This was confusing and messy.

Git solves this problem by keeping everything organized and clean.

Core Terminologies

CommandsExplanation
Repository (Repo)A folder where your project and its complete change history are stored.
CommitA saved snapshot of your code at a specific point in time.
BranchA separate version of your project used to work on new features.
Main / MasterThe main and stable branch of the project.
MergeCombining changes from one branch into another.
CloneMaking a copy of a remote repository on your local system.
PushSending your local code changes to a remote repository.
PullFetching the latest code from a remote repository to your system.
Staging AreaA place where changes are kept before committing them.
AddCommand used to move files to the staging area.
HEADPoints to the current branch or latest commit you are working on.
RemoteAn online version of your repository (like GitHub).
ConflictWhen Git cannot automatically merge changes.
ForkA personal copy of someone else’s repository.
CheckoutSwitching between branches or commits.
StatusShows the current state of your working directory.
LogShows the history of commits.
InitCreates a new Git repository.
FetchDownloads changes from remote without merging.
RebaseReapplies commits on top of another base commit.

These are the some main core concepts :

  1. A repository (repo) is a place where your project lives and Git tracks all its changes.

    It stores:

    1. Your project files

    2. Every version of those files

    3. Commit history

    4. Branches and changes

Simple example:

Think of a repository like a folder with memory
It not only holds your files but also remembers what changed, when, and by whom.

  1. A commit is like saving your work with a message so you can remember what you changed.

    Think of it as a checkpoint in your project — you can come back to it anytime.

    What does a commit do?

    When you commit:

    1. Git takes a snapshot of your staged files

    2. Saves them permanently in the repository

    3. Gives that snapshot a unique ID (hash)

Here is the example of the git commit:

git commit -m "your message"
  1. A branch is a separate line of development where you can work on new features or fixes without affecting the main code.

    Think of it like creating a copy of your project to experiment safely.

    Branches help you:

    1. Work on new features safely

    2. Fix bugs without breaking the main project

    3. Collaborate with teammates easily

Simple Example

You have a main project running fine. Now you want to add a new feature.

Instead of changing the main code, you create a branch:

git branch new-feature

Now you can work freely on new-feature.

  1. In Git, HEAD is a special pointer that represents your current working position in the repository. It usually points to the latest commit on the branch you are currently on.

If you’re diving into Git, you’ve probably come across the term HEAD. Sounds mysterious, right? Don’t worry—it’s simpler than it looks.

Think of HEAD as a bookmark or pointer in your project. It tells Git, “This is where I am right now!”

  1. HEAD Points to Your Current Spot

    Whenever you’re working on a branch (say main), HEAD points to the latest commit on that branch.

  2. Attached vs Detached HEAD

    1. Attached HEAD (Normal Mode):
      HEAD is “attached” to a branch. Any new commits go on this branch.

       HEAD -> main
       main -> latest commit
      
    2. Detached HEAD (Advanced Mode):

      if you checkout a specific commit instead of a branch, HEAD points directly to that commit.

       HEAD -> commit 123abc
      
  3. Handy HEAD Commands

git status          # See where HEAD is
git log -1 HEAD     # See the commit HEAD points to
git checkout main   # Move HEAD to main branch
git reset --hard HEAD~1  # Go back one commit (HEAD moves too)

There are many commands in Git but the common commands are as following:

CommandDescription
git initInitializes a new Git repository in a folder.
git clone <url>Copies a remote repository to your local system.
git statusShows the current state of files (modified, staged, untracked).
git add .Adds all changed files to the staging area.
git add <file>Adds a specific file to the staging area.
git commit -m "message"Saves changes with a message.
git pushUploads local commits to the remote repository.
git pullDownloads and merges updates from the remote repository.
git branchShows all branches in the project.
git branch <name>Creates a new branch.
git checkout <branch>Switches to another branch.
git checkout -b <branch>Creates and switches to a new branch.
git merge <branch>Merges another branch into the current branch.
git logShows commit history.
git diffShows changes between commits or files.
git remote -vShows linked remote repositories.
git fetchDownloads updates without merging.
git resetUndoes changes (use carefully).
git rm <file>Deletes a file from the repository.
git stashTemporarily saves unfinished changes.

But in these commands , most important one’s are :

  1. git init

git init It is used to initializes a new Git repository in a folder. Like this you can initializes the git in Bash or VS Code where you want

git init
  1. git add

git status is one of the most important Git commands. It tells you what is happening in your project right now. It tells you whether there is any update in program or not.

git status
  1. git add

git add is used to move your changes to the staging area so they can be saved (committed). we can write this command in two ways :

  1. git add basic.js(after git add write the name of file).

  2. git add . (This (.) means the all files in the folder).

git add basic.js

git add .
  1. git commit

git commit is used to save your staged changes permanently in Git with a message.

After you add files using git add, git commit:

  1. Saves those changes.

  2. Creates a checkpoint in your project history.

  3. Adds a message describing what you changed.

git commit -m "your message"

commit messages help you and others understand:

  1. What was changed

  2. Why it was changed

Good messages make your project easier to manage.

  1. git log

git log is a command that shows the history of commits in your current branch. If Git is like a time machine for your code, then git log is the control panel that shows all your past stops—all the commits you’ve made.

When you run git log:

git log

Then it shows:

commit 9a1b2c3d4e5f6g7h8i9j
Author: Mohit Kumar <mohit@example.com>
Date:   Tue Dec 31 2025

    Added new feature to homepage

Local repository structure overview

When you initialize a Git repository (git init), Git creates a .git folder.
This folder is the brain of Git — it stores everything about your project’s history.

Commit History Flow

Think of Git as a time machine for your project. Every time you save your work with a commit, Git remembers it. The commit history is like a timeline of all your changes, and understanding it helps you navigate your project easily.

Conclusion

Git is more than just a version control system—it’s your project’s personal time machine. It helps you track every change, collaborate with others, and experiment freely without fear of losing work.

With Git, you can:

  1. Save snapshots of your project with commits

  2. Work on multiple features simultaneously using branches

  3. Collaborate safely through remote repositories like GitHub

  4. Navigate project history effortlessly with HEAD, log, and checkout

In short, Git brings order, safety, and flexibility to your development workflow. Whether you’re working solo or in a team, mastering Git gives you confidence and control over your code.

Pro Tip: Think of Git as your project’s storybook—every commit is a page, every branch is a chapter, and HEAD shows the page you’re currently reading. Keep writing, merging, and exploring!

P
PRITAM ROY5mo ago

Bohut accha presentation hain bhai !!