# Git for Beginners: Basics and Essential Commands

#### ❗ Why GIT is present?

Easy & remove tough work for developer as `managing` & `check track` from into development process.

### Git as Distributed Version Control System

Every developer has a need full copy of the project with history of code file what updates in that.

* GIT node dependent on one single central server
    
* Also able to work offline & later sync with others
    

> GIT —&gt; has user control with collaboration power

---

## What is GIT?

Git is a —&gt; `Version Control System`

Git is a tool that helps you to `track changes in your code` and `manage versions safely`.

* `GIT`—&gt; time machine for your project code
    
* History Tracker
    
* Backup system with memory
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769854213715/9611815b-7965-4b9a-a101-70c0c6b16410.png align="left")

In GIT each `commit` has saved info as:

* What will be changed?
    
* Who that changed it?
    
* Which time to change it?
    

---

## Why Git is Used?

GIT concept can easily solve real developer problem -

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769856925949/3a07aea0-70f6-40a6-ac1b-592100be31ef.png align="left")

> * `GIT` almost used every **software company** in modern world.
>     
> * Git tracking files are also store in local storage.
>     

---

## GIT Basics and Core Terminologies

#### Repository (Repo)

`Repo` —&gt; is your project folder that git tracks & for storing,

* `Files`, `History`, `Versions`
    

Initialize git -

```bash
git init
```

GIT can created a hidden `.git/` folder (without start tracking).

#### Commit

`Commit` —&gt; snapshot of your project.

It includes - Author, Timestamp, Message, previous commit

Example - A commit is *like* `checkpoint` in a game

```pgsql
git commit -m "Added homepage with html & css code file"
```

#### Branch

`Branch` —&gt; a separate line of work.

It used for - New features, Testing to fixes bugs

Example - Default branch —&gt; `main`

#### HEAD

`HEAD` —&gt; pointer to `latest commit` of current branch.

Head shows where you are currently in history.

Git Workflow -

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769858943443/07cb101c-e4ed-4069-b421-ba4ec1356c8e.png align="left")

---

## Common Git Commands

Simple project in VS Code & workflow of that -

* Create project —&gt; Start Git —&gt; Make changes —&gt; Save versions —&gt; View history
    

Create project & initiate that -

* create folder `my-project` on computer & open with vscode
    
* create `my-project/index.html`
    

In terminal of vs code -

### Initialize Git

```bash
git init
```

`Git` is now activate for tracking.

Hidden `.git` folder is automatically created

* `git init` —&gt; <mark>Initialized empty git repository</mark>
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769859471554/4c00aec1-216e-4504-8783-604be39281a8.png align="left")

`Git` → will now start to track project.

Local Repository Structure -

```pgsql
my-project
│
├── .git
├── index.html
```

`.git` folder its **brain of our GIT** —&gt; Never delete it.

### Check Git Status

```bash
git status
```

`git status` —&gt; <mark>Check status of git</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769859604993/6d8dd59c-7818-44bd-8537-8742d8bed84f.png align="left")

`U - Untracked files` —&gt; “index.html” you will see the file ***but its not tracking it yet***.

### Add file to **Staging Area**

```bash
git add index.html
```

`git add <file_name>` —&gt; <mark>single file add for staging area</mark>

*\- - OR- -*

```bash
git add .
```

`git add .` —&gt; <mark>all files add for staging area</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769859899022/50939dba-a50f-44c4-9132-fb6693aab067.png align="left")

`git add <file_name>` OR `git add .` —&gt; file is ready to be saved.

### Make first Commit

Commit same as a save point in game like **checkpoint.**

```pgsql
git commit -m "Inital project heading"
```

`git commit -m “<message>“` —&gt; <mark>that process of save through meaningful message</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769860071122/05922258-0775-4d81-afc2-b67a14ed7555.png align="left")

---

Make a Changes -

* Through checking status see all info about that project
    
* Edit `index.html` & check status
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769860301052/96ff8985-57fe-4cfc-a867-1776ec2a44df.png align="left")

`M - Modified files` =&gt; “index.html” you will see commit again, it’s our new version that saved.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769860511300/56f09e51-7535-4fae-93b3-f3fc0bcdddb8.png align="left")

### View History

```pgsql
git log
```

* `git log` —&gt; <mark>remember that all activates</mark>
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769860826215/bd8dd787-3f50-439e-9f0e-50cc918293f8.png align="center")

`GIT` —&gt; can remembers every version.

---

## Conclusion

Git Workflow -

1\] Initialize Git —&gt; `git init` —&gt; creates `.git/` folder

2\] Check status —&gt; `git status` —&gt; changed, staged, untracked files

3\] Add files —&gt; `git add .` —&gt; staging area

* Git, remember this change & file moves to staging area.
    
* Example - `git add file.txt`
    

4\] Commit —&gt; save this snapshot.

* Example - `git commit -m "Added login feature"`
    

5\] log —&gt; `git log` —&gt; shows commit history
