Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Updated
3 min read
Git for Beginners: Basics and Essential Commands

Today, Git is one of the most essential tools for developers. Git helps you track changes, manage code, and collaborate efficiently, whether you are working alone or in a team. This blog will walk you through what Git is, why it’s used, its core concepts, and the most common commands—step by step.

What is Git?

Git is an open-source version control system that acts like a "Time Machine" for your project.

In simple terms, it tracks every change you make to your source code, allowing you to revert to previous versions if something breaks. Unlike older systems that rely on a central server, Git is distributed—meaning every developer has a complete copy of the project's entire history on their local computer. This makes it incredibly fast, reliable for offline work, and ensures that multiple people can collaborate on the same files simultaneously without accidentally overwriting each other's work.

Why Git is Used

Git is the industry standard for three major reasons:

  • Tracking Changes: Git keeps a granular history of every line of code you modify. If a bug appears, you can "travel back in time" to see exactly when and where the logic changed.

  • Seamless Collaboration: Git allows multiple developers to work on the same codebase simultaneously. It uses a "merge" system to combine everyone's work, ensuring that your teammate's new feature doesn't accidentally overwrite your bug fix.

  • Experimentation: You can create "branches" to try out risky new ideas. If the experiment fails, you simply delete the branch; your main project remains untouched and "clean."

Git Basics and Core Terminologies

Before jumping into commands, you need to understand the "Big Four" concepts:

  • Repository (Repo): A folder where Git tracks all the changes. It’s the "project container."

  • Commit: A snapshot of your files at a specific point in time. Think of it as a permanent record in the project's history.

  • Branch: A parallel version of your repository. It allows you to develop features without affecting the main code.

  • HEAD: A pointer that tells Git which branch or commit you are currently looking at.

The Three Stages of Git

Understanding how Git moves files is crucial. Files exist in one of three states:

  1. Working Directory: Where you are currently editing files.

  2. Staging Area (Index): A "prep zone" where you pick which changes you want to include in your next snapshot.

  3. Local Repository: Where Git permanently stores the snapshots (commits).

Common Git Commands and

Let's put these concepts into practice with essential commands.

Initialization and Setup

  1. git init: Initializes a new Git repository in your current directory. A hidden .git folder is created to store all history.

     git init
    

The Basic Workflow

  1. git status: Checks the state of your working directory and staging area. It tells you which files are modified, which are staged, and which are untracked. Run this frequently!

     git status
    
  2. git add <file>: Adds a specific file (or use git add . for all files) from your working directory to the staging area.bash

     git add index.html
     # or to add all changes:
     git add .
    
  3. git commit -m "message": Records the staged changes as a new commit in the local repository. The -m flag lets you attach a descriptive message.bash

     git commit -m "Add initial HTML structure for homepage"
    

Viewing History

  1. git log: Displays a log of all previous commits in the current branch. You can see who committed what, when, and their message.

     git log
    

Wrapping Up: Your Journey with Git

Git is more than just a tool; it’s a safety net that gives you the confidence to experiment and build complex projects. While the command line might feel intimidating at first, these five basic commands—init, status, add, commit, and log—will handle 90% of your daily work.

More from this blog

subhajit bag

13 posts