Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Published
3 min read

A beginner-friendly guide to understanding Git from scratch

## Introduction

You’ve probably heard about Git or GitHub—but have you ever thought about how software engineers from different cities or even different countries work on the same codebase simultaneously?

More importantly, how are these changes tracked, reviewed, and reverted if something goes wrong?

## What is Git?

This is where Git comes to the rescue - a distributed version control system that helps developers track changes in their code and collaborate efficiently without any conflict.

## Git vs GitHub

While Git can track changes locally, to collaborate with others it requires a shared remote repository like GitHub. GitHub is a web-based platform that hosts Git repositories and enables developers to collaborate, review code, and manage projects online.

Git lets developers make changes to code, track those changes, and revert them if needed. Its distributed approach gives each developer a complete copy of the project and its full history on their local machine. This means developers can work offline, commit changes locally, and push them to GitHub when ready.

## How Git Works Behind the Scenes

For Git to work, you need to first initialize your project with Git and once you do that - it creates a hidden .git folder, and your project folder becomes Git repository and is now tracked by Git.

Your .git folder stores:

- Complete history of all commits

- Branch information

- Metadata about changes

- References to remote repositories

A Git repository is a project folder that contains a .git directory.

## Git’s Three Core Areas

Working Directory - This is your actual project folder where you create, modify, and delete files. Changes are not tracked yet; Git only sees them but has not saved them.

/myProject

├── index.js

├── app.js ← edited here

└── .git

Staging Area – A temporary area where you decide which changes will be included in your next commit.

Repository (Local) – Where changes are permanently saved. It contains all commits and history, with each commit representing a snapshot of the project.

Working Directory

git add

Staging Area

git commit

Local Repository

## How Git Stores Data

Git is efficient in how it stores data. If a file has not changed, Git does not create a new copy of it; instead, it reuses the version from the previous snapshot. This avoids unnecessary duplication while still allowing each commit to represent the complete state of the project at that moment.

## Git Commands for Beginners

- git init – Creates a new Git repository in the current folder.

- git status – Shows which files are staged, modified, or untracked.

- git add – Adds changes to the staging area.

- git commit – Saves staged changes as a snapshot in the repository.

- git log – Displays the commit history.

- git diff – Shows differences between file versions.

## Conclusion

Learn the basics, practice regularly, and Git will quickly become an indispensable tool in your developer journey.