Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Updated
3 min read

Git is one of the most important tools a developer must learn. It helps manage code changes, avoid mistakes, and collaborate efficiently.

This blog explains what Git is, why it’s used, core Git concepts, and essential commands, with a simple workflow that beginners can easily follow.

What is Git ?

Git is a distributed version control system that records changes in code and allows developers to manage different versions of a project.

Git helps you manage changes to your code over time. It keeps track of every little change or update you make, you can always look back at previous versions or undo mistakes if needed.

Why does Git exists ?

When writing code, files change constantly. Without a system like VCS, it becomes difficult to :

  • track changes or undo mistakes.

  • Work on new features without breaking existing code.

  • Collaborate with other developers

Git solves these problems by giving developers control while working on code.

Git Basics and Core Terminologies

Before using Git commands, it’s important to understand a few core concepts.

  1. Repository : A repository (repo) is a project folder tracked by Git. It contains Project files and the hidden .git folder.

  2. Commit : A commit is a snapshot of the project at a specific point in time.

    Each commit includes: the changes made, a unique id, and the meesage describing the changes.

  3. Branch : A branch is a separate line of development. the repo can have more than one branches.

  4. Head : HEAD is a pointer that indicates the current commit or branch you are working on.

Common git commands

  1. git init : Initialize a Repository.

     git init
    

Creates a new Git repository by adding a .git directory to the project.

  1. git status : Shows modified, staged, and untracked files.

     git status
    
  1. git add <file_name> : Moves selected changes to the staging area.

     git add <file_name> // to stage the single file with <file_name>
           or
     git add .   // to stage all the changed files
    
  1. git commit : save changes from the staging area.

     git commit -m "commit_message"
    
  1. git log : log the commit history

     git log  // detailed commits 
         or
     git log --oneline  // details in one line related to commits
    

Understanding the Git Workflow

  1. git init

    This command converts a normal folder into a Git-tracked repository. Git creates a hidden .git directory. From this point, Git starts monitoring changes.

  2. Working Directory

    The working directory is your project folder where you write code, edit files or delete or modify content.

    At this stage: Git sees the changes but nothing is saved yet.

  3. git add <file_name>

    This moves selected changes to the staging area . You decide exactly what will be included in the next commit.

  4. Staging Area

    The staging area is a temporary holding space.

  5. git commit -m “<commit_message>“

    This command creates the commit. The commit is stored in the local repository. Each commit becomes part of the project history.

git push origin <branch_name>

Uploads local commits to a remote repository (GitHub, GitLab, etc.) Used for collaboration and backups

Until you push, your code exists only locally.

Let’s Connect

If you’re also learning Git or just starting your developer journey, feel free to connect with me.

🔗 Github

🔗 X account

Happy coding guys…