Back to all posts

Git Tutorial for Beginners: Learn Git from Scratch

Introduction If you are a software developer, data engineer, SQL developer, or anyone who writes code, learning Git is one of the most important skills you c...

Introduction

If you are a software developer, data engineer, SQL developer, or anyone who writes code, learning Git is one of the most important skills you can have.


What is Git?

Git is a Version Control System (VCS).

It helps developers keep track of every change made to their code.

Think of Git as a time machine for your project. If something goes wrong, you can easily return to an older working version.


Why Do We Need Git?

Imagine you're working on a project without Git.

Your project folder might look like this:

SQL
Project
Project_Final
Project_Final_New
Project_Final_Latest
Project_Final_Updated

After a few days, you won't even remember which folder contains the latest code.

Git solves this problem by storing every version inside a single project.

Instead of creating multiple folders, Git stores the history internally.

SQL
Version 1
↓

Version 2
↓

Version 3
↓

Version 4

You can restore any previous version whenever you want.


What is Version Control?

Version Control means keeping a record of every change made in your project.

Git stores information such as:

  • Who made the change

  • When the change was made

  • What files changed

  • Why the change was made

This makes collaboration much easier.


Git vs GitHub

One of the biggest beginner mistakes is thinking Git and GitHub are the same.

Git

GitHub

Software installed on your computer

Cloud platform for hosting repositories

Works offline

Requires internet for synchronization

Tracks file changes

Stores repositories online

Manages version history

Enables collaboration

Workflow

SQL
Laptop
   │
   ▼
 Git
   │
   ▼
GitHub

Git manages your code locally, while GitHub stores a copy online.


Important Git Terminology

Repository (Repo)

A Repository is simply your project folder that Git manages.

Example:

SQL
EmployeeManagement

or

SQL
ReadDocumentAI

Every Git project is called a Repository.


Commit

A Commit is like saving a checkpoint.

Whenever you finish a logical piece of work, you create a commit.

Think of it like SQL Server:

SQL
BEGIN TRANSACTION

UPDATE Employee
SET Salary = Salary + 5000

COMMIT

Similarly, in Git:

Bash
git commit

Once committed, your changes become part of the project's history.


Branch

A Branch is an independent line of development.

By default, every repository starts with:

SQL
main

Suppose you're working on new features.

SQL
main

feature-login

feature-dashboard

bug-fix

Each developer works on a separate branch without affecting the main project.


Clone

Clone means downloading an existing repository.

SQL
GitHub
   │
   ▼
Your Computer

Command:

Bash
git clone repository-url

Push

Push uploads your local commits to GitHub.

SQL
Laptop
   │
   ▼
GitHub

Pull

Pull downloads the latest changes from GitHub.

SQL
GitHub
   │
   ▼
Laptop

Understanding the Git Workflow

Every Git project follows the same workflow.

SQL
Create or Modify File
        │
        ▼
git add
        │
        ▼
git commit
        │
        ▼
git push

This simple cycle is repeated throughout development.


Installing Git

After installing Git, verify the installation.

Bash
git --version

Example:

SQL
git version 2.49.0

Configure Git

Before using Git, configure your username and email.

Bash
git config --global user.name "Your Name"

git config --global user.email "you@example.com"

Verify your configuration:

Bash
git config --list

Creating Your First Git Repository

Create a project folder.

SQL
GitDemo

Open Terminal or Command Prompt.

Bash
cd GitDemo

Initialize Git.

Bash
git init

Output:

SQL
Initialized empty Git repository

Git creates a hidden folder called:

SQL
.git

This folder stores the complete version history of your project.


Create Your First File

Create a file named:

SQL
README.md

Add some text.

SQL
Hello Git

Check Repository Status

Run:

Bash
git status

Output:

SQL
Untracked files:

README.md

This means Git has detected the file, but it is not yet being tracked.


Understanding Git's Three Stages

This is one of the most important Git concepts.

SQL
Working Directory
        │
        ▼
Staging Area
        │
        ▼
Repository

Or simply:

SQL
File

↓

git add

↓

Staging Area

↓

git commit

↓

Repository

Working Directory

Where you create or edit files.

Staging Area

Where you tell Git which changes should be included in the next commit.

Repository

Where Git permanently stores your commits.


Stage Your Changes

Add a single file:

Bash
git add README.md

Add every modified file:

Bash
git add .

Create Your First Commit

Bash
git commit -m "Initial commit"

Example Output:

SQL
1 file changed
create mode 100644 README.md

Congratulations! Your first Git commit has been created.


View Commit History

Display the complete history.

Bash
git log

Compact version:

Bash
git log --oneline

Example:

SQL
a8f22 Initial commit

Beginner Commands Summary

Command

Purpose

git --version

Check Git installation

git init

Initialize a repository

git status

Check repository status

git add

Stage changes

git commit -m "message"

Save changes

git log

View commit history

git log --oneline

Compact commit history


Common Beginner Mistakes

  • Forgetting to run git add before committing.

  • Writing unclear commit messages like "Update" or "Fix".

  • Committing unfinished work.

  • Confusing Git with GitHub.

  • Ignoring git status, which is one of the most useful commands.


What's Next?

Now that you've learned the basics, the next topics are:

  • Git Ignore (.gitignore)

  • Git Diff

  • Git Restore

  • Git Reset

  • Git Branch

  • Git Merge

  • GitHub Repositories

  • Git Push and Pull

  • Merge Conflicts

  • Pull Requests (PRs)

Mastering these concepts will prepare you for real-world software development and technical interviews.


Conclusion

Git is not just a collection of commands—it is a system for managing your project's history safely and efficiently.

Once you understand the workflow:

SQL
Working Directory
      ↓
git add
      ↓
Staging Area
      ↓
git commit
      ↓
Repository
      ↓
git push
      ↓
GitHub

you'll find that Git becomes an essential part of your daily development workflow.

0 likes

Rate this post

No rating

Tap a star to rate

0 comments

Latest comments

0 comments

No comments yet.

Keep building your data skillset

Explore more SQL, Python, analytics, and engineering tutorials.