# Git for Beginners: Basics and Essential Commands

Before Git became widely used in software engineering, developers still wrote and debugged code successfully. This raises an important question: if developers could work without Git, why do we need it today?

To understand the importance of Git, let us look at how development worked before version control systems existed.

Imagine two developers, Aman and Rahul, working on the same project. Aman is developing the project on his local system but needs Rahul’s help to implement some features. Aman copies the project onto a pen drive and shares it with Rahul. Rahul makes changes to the code and returns the pen drive to Aman.

At this point, a serious problem arises. Aman has no clear way to identify:

* Which code was written by him
    
* Which lines were modified by Rahul
    
* What exactly changed between versions
    

There is no reliable way to track changes, maintain history, or revert mistakes. This is where **Git** comes into the picture.

Git solves this problem by tracking every change made to the codebase. This process is known as **version control**, and Git is a **Version Control System (VCS)** that helps developers manage, track, and collaborate on code efficiently.

Now Let’s understand Important Commands in Git

```plaintext
git init
```

This command initializes a new Git repository in the current project. It creates a hidden .git folder that allows Git to start tracking changes.

```plaintext
git checkout -b "new_branchName"
```

For creating a new branch and also switch to that new\_branch

```plaintext
git checkout “exists_branchName”
```

Only for switching to exists branch

```plaintext
git add (fileName)
```

Adds a specific file to the staging area so it can be included in the next commit.

```plaintext
git add .
```

Adds **all new and modified files** in the current directory to the staging area.

```plaintext
git commit -am “added + commited”
```

This command stages only modified files that are already tracked and commits them in a single step. It does not include new untracked files.

```plaintext
git commit -m “commit_message”
```

Creates a commit with a meaningful message describing the changes made. Each commit acts as a screenshort of the project at a specific point in time.
