# Git for Beginners: Basics and Essential Commands

## 1\. What is Git?

![https://miro.medium.com/v2/resize%3Afit%3A1400/1%2AE1jdYRKin1hraL67-cKALw.png](https://miro.medium.com/v2/resize%3Afit%3A1400/1%2AE1jdYRKin1hraL67-cKALw.png align="left")

![https://homes.cs.washington.edu/~mernst/advice/version-control-fig3.svg](https://homes.cs.washington.edu/~mernst/advice/version-control-fig3.svg align="left")

Git is a **version control system**.  
In simple words, Git helps us **track changes in our code over time**.

Git is also a **distributed version control system**, which means:

* Every developer has a full copy of the project
    
* Work can be done offline
    
* No single central computer controls everything
    

So instead of saving files like `project_final_v2_`[`last.py`](http://last.py), Git keeps proper versions for us.

## 2\. Why Git is Used

![https://media.licdn.com/dms/image/v2/C5612AQFfYpEY8j_3LA/article-cover_image-shrink_600_2000/article-cover_image-shrink_600_2000/0/1520244974622?e=2147483647&t=GLQuYQ-pVEmr2ZauVVm3suVkI6XwPM4mA06grdLYUL4&v=beta](https://media.licdn.com/dms/image/v2/C5612AQFfYpEY8j_3LA/article-cover_image-shrink_600_2000/article-cover_image-shrink_600_2000/0/1520244974622?e=2147483647&t=GLQuYQ-pVEmr2ZauVVm3suVkI6XwPM4mA06grdLYUL4&v=beta align="left")

![https://wac-cdn.atlassian.com/dam/jcr%3Acc0b526e-adb7-4d45-874e-9bcea9898b4a/04%20Hotfix%20branches.svg?cdnVersion=3151](https://wac-cdn.atlassian.com/dam/jcr%3Acc0b526e-adb7-4d45-874e-9bcea9898b4a/04%20Hotfix%20branches.svg?cdnVersion=3151 align="left")

Git is used because it makes development easier and safer.

Some main reasons:

* We can **track changes** in our code
    
* We can **go back** to older versions if something breaks
    
* Multiple people can **work together** on the same project
    
* Mistakes are not permanent
    

For college projects, internships, and real jobs, Git is almost mandatory.

## 3\. Git Basics and Core Terminologies

![https://git-scm.com/book/en/v2/images/branch-and-history.png](https://git-scm.com/book/en/v2/images/branch-and-history.png align="left")

![https://www.dasca.org/content/images/main/git-terminology.jpg](https://www.dasca.org/content/images/main/git-terminology.jpg align="left")

Before using Git commands, it’s important to understand some basic terms.

### Repository (Repo)

A repository is a **folder tracked by Git**.  
It contains:

* Project files
    
* Git history
    

Created using:

```abap
git init
```

---

### Commit

A commit is a **saved snapshot of the project** at a point in time.

Think of it like:

> “This is my project state right now, and I want to save it.”

---

### Branch

A branch is a **separate line of development**.  
It allows us to:

* Experiment safely
    
* Work on features without breaking main code
    

---

### HEAD

`HEAD` is a **pointer to the current commit** you are working on.  
Usually, it points to the latest commit of the current branch.

## 4\. Common Git Commands

![https://www.edureka.co/blog/wp-content/uploads/2016/11/Git-Architechture-Git-Tutorial-Edureka-2.png](https://www.edureka.co/blog/wp-content/uploads/2016/11/Git-Architechture-Git-Tutorial-Edureka-2.png align="left")

![https://geo-python.github.io/site/2018/_images/Git_illustration.png](https://geo-python.github.io/site/2018/_images/Git_illustration.png align="left")

These are the **most important Git commands for beginners**.

---

### `git init`

Initializes a Git repository.

```abap
git init
```

---

### `git status`

Shows:

* Modified files
    
* Staged files
    
* Untracked files
    

```abap
git status
```

---

### `git add`

Adds files to the staging area.

```abap
git add file.txt
git add .
```

---

### `git commit`

Saves staged changes as a commit.

```abap
git commit -m "Initial commit"
```

---

### `git log`

Shows commit history.

```abap
git log
```

## 5\. Basic Developer Workflow Using Git

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

![https://media2.dev.to/dynamic/image/width%3D800%2Cheight%3D%2Cfit%3Dscale-down%2Cgravity%3Dauto%2Cformat%3Dauto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvpxeexqyfvf4hw3zxtbn.png](https://media2.dev.to/dynamic/image/width%3D800%2Cheight%3D%2Cfit%3Dscale-down%2Cgravity%3Dauto%2Cformat%3Dauto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvpxeexqyfvf4hw3zxtbn.png align="left")

Here’s how a beginner typically uses Git from scratch:

### Step-by-step workflow

1. Create a project folder
    
2. Initialize Git
    
    ```abap
    git init
    ```
    
3. Write or modify code
    
4. Check status
    
    ```abap
    git status
    ```
    
5. Stage changes
    
    ```abap
    git add .
    ```
    
6. Commit changes
    
    ```abap
    git commit -m "Added main logic"
    ```
    
7. View history
    
    ```abap
    git log
    ```
    

---

### Git Flow (Conceptual)

```abap
Working Directory
        ↓
   Staging Area
        ↓
     Repository
```

This flow is the **core idea of Git usage**.

## 6\. Commit History Flow

![https://nvie.com/img/git-model%402x.png](https://nvie.com/img/git-model%402x.png align="left")

![https://user-images.githubusercontent.com/1256329/80170009-f9d03200-85b4-11ea-94d3-3041887565ac.png](https://user-images.githubusercontent.com/1256329/80170009-f9d03200-85b4-11ea-94d3-3041887565ac.png align="left")

Each commit points to the previous one, forming a history.

```abap
Commit 1 → Commit 2 → Commit 3 → Commit 4
```

This makes it easy to:

* Track progress
    
* Debug issues
    
* Understand how a project evolved
    

---
