# Git for Beginners: A Simple Guide to Version Control

If you’re starting your developer journey, one of the first tools you’ll hear about is **Git**.  
Git helps you track changes in your code, collaborate with others, and safely experiment without fear of losing work.

This article explains **what Git is**, **why it’s used**, and **how to use it step by step**, even if you’re completely new.

---

## What is Git?

Git is a **distributed version control system**.

In simple terms:

* It **tracks changes** in your files
    
* It lets you **save versions** of your project
    
* It allows **multiple developers** to work on the same code without conflicts
    

Unlike older systems, Git gives **every developer a full copy of the project history** on their own machine.

---

## Why is Git Used?

Git is used because it helps developers:

* ✅ Track who changed what and when
    
* ✅ Roll back to earlier versions if something breaks
    
* ✅ Work on features without affecting the main code
    
* ✅ Collaborate efficiently with teams
    
* ✅ Maintain a clean and reliable project history
    

Whether you’re working solo or in a team, Git is essential.

---

## Git Basics & Core Terminologies

Before running commands, let’s understand some key Git concepts.

### Repository (Repo)

A **repository** is a project folder that Git is tracking.

It contains:

* Your project files
    
* A hidden `.git` directory that stores history and metadata
    

---

### Commit

A **commit** is a snapshot of your project at a specific point in time.

Think of it like:

> “Save game” 🎮 for your code

Each commit has:

* A unique ID (hash)
    
* A message describing the change
    

---

### Branch

A **branch** lets you work on features independently.

* `main` (or `master`) → stable code
    
* feature branches → experiments or new features
    

---

### HEAD

`HEAD` is a pointer to the **current commit you’re working on**.

Usually, it points to the latest commit on the current branch.

![https://miro.medium.com/1%2AdiRLm1S5hkVoh5qeArND0Q.png](https://miro.medium.com/1%2AdiRLm1S5hkVoh5qeArND0Q.png align="left")

Git works in **three main areas**:

1. **Working Directory** – where you edit files
    
2. **Staging Area** – where you prepare files for commit
    
3. **Repository** – where commits are permanently stored
    

---

## Common Git Commands (With Examples)

Let’s see the most important Git commands used daily.

### 1\. `git init`

Creates a new Git repository.

```plaintext
git init
```

Use this inside your project folder.

---

### 2\. `git status`

Shows the current state of your files.

```plaintext
git status
```

It tells you:

* Which files are modified
    
* Which files are staged
    
* What’s not tracked yet
    

---

### 3\. `git add`

Moves changes to the staging area.

```plaintext
git add file.txt
```

Or add everything:

```plaintext
git add .
```

---

### 4\. `git commit`

Saves staged changes to the repository.

```plaintext
git commit -m "Add initial project files"
```

💡 Always write clear commit messages.

---

### 5\. `git log`

Shows the commit history.

```plaintext
git log
```

You’ll see:

* Commit IDs
    
* Author
    
* Date
    
* Commit message
    

![https://user-images.githubusercontent.com/44003176/103466403-36a81780-4d45-11eb-90cc-167d210d7a52.png](https://user-images.githubusercontent.com/44003176/103466403-36a81780-4d45-11eb-90cc-167d210d7a52.png align="left")

![https://i.sstatic.net/Hg5bt.png](https://images.openai.com/thumbnails/url/GObS43icu5mZUVJSUGylr5-al1xUWVCSmqJbkpRnoJdeXJJYkpmsl5yfq5-Zm5ieWmxfaAuUsXL0S7F0Tw7yqoxIcnNPTwwoic8rKXGLLzdzyqgs8TPzMCyI8vcvDw2pMi4tSPPLCUoO9c80DixXKwYAdisnAA align="left")

---

### 6\. `git branch`

Lists or creates branches.

```plaintext
git branch
```

Create a new branch:

```plaintext
git branch feature-login
```

---

### 7\. `git checkout`

Switch between branches.

```plaintext
git checkout feature-login
```

(Modern alternative: `git switch`)

## A Simple Git Workflow (From Scratch)

![https://humbletoolsmith.com/img/posts/a-look-inside-the-_git-folder/Git%20Folder%20Internals.png](https://humbletoolsmith.com/img/posts/a-look-inside-the-_git-folder/Git%20Folder%20Internals.png align="left")

![https://nevrenato.github.io/CSAIL_Git/images/git_workflow.png](https://nevrenato.github.io/CSAIL_Git/images/git_workflow.png align="left")

Let’s walk through a basic developer workflow.

```plaintext
mkdir my-project
cd my-project
git init
```

Create a file:

```plaintext
echo "Hello Git" > readme.txt
```

Check status:

```plaintext
git status
```

Stage the file:

```plaintext
git add readme.txt
```

Commit:

```plaintext
git commit -m "Add readme file"
```

Check history:

```plaintext
git log
```

🎉 You’ve successfully used Git!
