Git Basics from A to Z

This article explains Git in simple, practical language. It covers the core ideas and the commands most developers use every day.

What Git is

Git is a version control system. It tracks changes in files and lets developers move through different versions of a project.

Think of Git as a time machine for code. It helps with:

Why teams use Git

In production work, Git helps teams keep a clear record of changes. It also makes code reviews and rollback easier.

A typical service team may have:

This structure keeps changes organized and reduces conflict.

Install Git

On Windows, use Git for Windows from the official Git website.

Check the installation:

git --version

Example output:

git version 2.45.0.windows.1

Initialize a repository

Create a folder and start a Git repo:

mkdir my-project cd my-project git init

This creates a hidden .git folder that stores repository metadata.

Check repository status

git status

This shows:

Basic workflow

git add file.txt git commit -m "Add initial file"

A commit is a saved snapshot of the project.

Example

echo "Hello from Git" > hello.txt git add hello.txt git commit -m "Add hello file"

The commit message should describe the change clearly.

Add and commit

The typical flow is:

git add . git commit -m "Implement login validation"

Important rule:

The .gitignore file

A .gitignore file tells Git which files should not be tracked.

Example:

node_modules/ .env bin/ *.log

This is useful for:

View history

git log

This shows commit history with messages and hashes.

You can make it easier to read:

git log --oneline --decorate --graph --all

See changes between versions

git diff

This shows file changes not yet committed.

To compare a committed version:

git diff HEAD~1 HEAD

The meaning of git add, git commit, git push

A beginner-friendly way to remember it:

Connect to a remote repository

If the repository is on GitHub, GitLab, or Azure Repos:

git remote add origin https://github.com/your-user/my-project.git git push -u origin main

The -u flag sets the branch tracking relationship.

Cloning a repository

git clone https://github.com/your-user/my-project.git

This downloads the repository and creates a working copy on the local machine.

Production example

A team may use Git to track app code, infrastructure scripts, and deployment manifests together. Each feature gets its own branch and each change is reviewed before merging.

Common pitfalls

Key takeaways