# Git 101

## Can we relate?

As familiar as Microsoft Office, Dropbox, and Facebook are to us, they have become part of our everyday lives.

Let’s use those as references:

Do you know that button in **Microsoft Word** that says “Edit, Undo”? Git does that but for every change that has ever been made to a project and by any member of your team.

You know that **Track Changes** feature in **Word** with all the red and blue lines showing who changed what? Git does that and it includes comments so you can explain why things were changed.

You know how **Dropbox** backs up your files **in the cloud**, but you still have a local copy on your computer (and maybe your iPhone, too)? GitHub does that for your code.

Do you know how **Facebook** has **Like** buttons and **threaded comments** and pictures of your friends and their adventures? While non-programmers find Git to be about as exciting as a fax machine, GitHub makes the process of working on a project through Git feel like using Facebook.

Now, let’s conclude this. Git is a version control system for tracking changes in files enabling coordination with multiple people working on a project.

That’s how we make software, right? Coordinating with the people. I feel like it’s useful in software development. I’ll be checking it. I hope you are following me.

## Installation

For **Linux** :

`apt install git`

For **Mac** *(with brew)* :

`brew install git` For **Windows** :

*Visit* [https://git-scm.com/download/win](https://git-scm.com/download/win) *and download*.

## Usage

* For the proper demonstration of Git, I’m creating a directory (folder) named **learning-git**. I am assuming this folder is my project folder where I will be working on.
    
* Now I’m opening the folder we created, on the Terminal or Command Prompt. I am assuming you’re familiar with basic Terminal commands. `cd learning-git`
    
* Now we are on the folder root we just created. Let’s initialize our folder as a **Git Project**. `git init`
    

```shell
arjun@techy:~/workspace/learning-git$ git init
Initialized empty Git repository in /home/arjun/workspace/learning-git/.git/
```

* Now I’m creating a file name hello\_world.c to work on.  
    `touch hello_world.c`
    

This command creates a file on Linux Based systems. I am assuming you can create files on Windows OS too.

* Let’s write some code on the file hello\_world.c we recently created.
    

```c
#include  <stdio.h>

int main()  {
    printf("Hello, World!");
    return  0;
}
```

* Now, I am checking does writing some code on the file results to some changes in Git Project or not. For this, I am checking the **status** of the Git Project. `git status`
    

```shell
arjun@techy:~/workspace/learning-git$ git status
On branch master

No commits yet

Untracked files:
    (use "git add <file>..." to include in what will be committed)

    hello_world.c

nothing added to commit but untracked files present (use "git add" to track)
```

* We can observe that Git System is labeling our file as **untracked**. Let’s keep the file on track by adding. `git add hello_world.c`
    
* In Git, every update needs to be committed with a message. This helps us in recognizing the changes we made. So, let’s **commit** the file with a message we added earlier. `git commit -m " This is the first program I wrote. "`
    

```shell
arjun@techy:~/workspace/learning-git$ git commit -m " This is the first program I wrote. "
[master (root-commit) 170953b]  This is the first program I wrote.
1 file changed, 6 insertions(+)
create mode 100644 hello_world.c
```

* Let’s check the status of the project I’m working on. `git status`
    

```shell
arjun@techy:~/workspace/learning-git$ git status
On branch master
nothing to commit, working tree clean
```

* Now I want to see what **series of changes** *(log)* I have made. Don’t get intimidated, it’s not a mathematical log. `git log`
    

```shell
arjun@techy:~/workspace/learning-git$ git log
commit 170953be4e6fb8f1acdebe6c7c0bd6b897c839ca (HEAD -> master)
Author: thearjun <mailarjunadhikari@gmail.com>
Date:   Sun Feb 2 20:29:56 2020 +0545

        This is the first program I wrote.
```

Looks like we’ve learned how to add files on the Git System.

Thanks for reading.
