# Git for Beginners

## **What exactly git is ?**

Git is a **version control system.**

It helps us:

* Save different versions of our code.
    
* Track changes in files
    
* Revert to old code if something goes wrong
    

If we change something in our code, we **lose** the old version.

**Git** help to solve this problem. It **save** all versions of our code.

While writing code, we create **multiple versions** as we make changes and improvements.

Git **saves** all these **versions** automatically.

If we later realize that a **mistake** was made in any version, **Git** helps us **track the changes** and **go back to a previous working version** easily.

This makes coding **safer** and helps avoid losing important code.

## **Why was Git invented?**

Imagine this situation:

I write some code and share it with Anushka using a pendrive.

Anushka adds new features and gives the code back to me.

Now you start wondering:

* What changes did Anushka make?
    
* Did anything break in the code?
    
* What if I want the old version back?
    
* What if both of us want to work on the project at the same time?
    

This is not really a coding problem. It is a problem of **managing changes**.

Git **exists** to solve this. Git **keeps track of every change** made to the code and allows multiple people to work on the same project safely, without confusion. This makes **collaboration** easy and reliable.

## **What is GitHub?**

*GitHub is a* ***Server.***

GitHub is a place on the internet where Git projects are **stored and shared.**

Git and GitHub are different things. It works with Git and helps developers save their projects on the internet.

When working alone on code, we only use Git. However, when we need to **collaborate** with others, we use GitHub.

GitHub allows us to:

* Upload code from our computer.
    
* Share code with others.
    
* Collaborate on the same project.
    
* Maintain a backup of our code.
    

## **Basic of Git**

### **1\. Repository**

A repository is a place where your project and its history are stored.

👉 Example: A folder that Git tracks.

### **2.Version**

A version is a saved state of your code.

👉 Example: First working code, second update, bug-fixed code.

### **3.Commit**

A commit in Git refers to **saving changes** to the repository with a **descriptive message**.

It acts as a **snapshot** of your project's current state, allowing you to track and manage changes over time.

For example, you might commit with a message like “Login feature added” to indicate what changes were made in that particular commit.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768578939491/efd9b75b-571f-42d0-8dac-fd2002b90b68.png align="center")

### **4.Branch**

A branch is a **separate line of work**.

we use it when we want to **try** new features **without affecting** main code.

### **5.Main**

The main branch contains the stable and working code.

### **6.Conflict**

A conflict happens when Git is confused about which change to keep.

👉 Example: Two people edit the same line.

### **7\. Staging Area**

A place where files are kept before committing.

👉 Example: Preparing files to save.

### **8\. HEAD**

HEAD points to the **current commit** you are working on.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768575117741/7df1432b-6eb0-487c-af75-4b11b597bee6.png align="center")

## Some basic commands:

### **1\. Git init**

**Start tracking.**

This command **creates** a Git repository.

Git now watches your project and remembers changes.

### **2\. Git status**

**Check current state.**

Shows:

Which files are new. Which files are modified.

Which files are staged.

It helps you know what to do next.

### 3\. Git add

**move to staging.**

This command tells Git:

“These changes are ready to be saved.”

Files go to the staging area.

### **4\. Git commit**

**Save a version.**

This command saves the staged changes permanently.

Each commit is a version of your project with a message.

### **5\. Git log**

**See past versions.**

Shows a list of all commits.

You can see: Commit id Date Message Useful when you want to go back.

### **6\. Git diff**

**See exact changes.**

Shows line-by-line difference between old and new code.

Very helpful before committing.

### **7\. Git revert**

**Undo safely.**

This command undoes a commit by creating a new commit.

Old history stays safe.

Best when working in a team.

### **8\. Git reset**

**Move HEAD back.**

This command moves your project to an older commit.

History can change.

Used carefully.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768578271116/86735655-cd9a-4485-b8b1-d442ac258b50.png align="center")

### **9\. Git reset --hard**

**Delete changes.**

This command:

Removes uncommitted changes .

Resets code completely .

We do not use it often because changes are lost permanently.

## ***Conclusion***

Git helps us to manage changes safely in a projects. Git saves every version of your work, lets you go back anytime, and makes collaboration easy with simple concepts and commands. Git removes confusion and gives full control over your project history.

I hope that you’ve found this blog helpful...! If you have any questions or feedback, feel free to leave a comment below.

If you found this article helpful, please like and share it .
