DEV Community

Arjun Adhikari
Arjun Adhikari

Posted on

Git 101 - Installation and First Commit

Imagine you people are familiar with Microsoft Office, Dropbox and Facebook. Obviously, everyone is.

Let's use those as references:

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.

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 with 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 and download.

Usage

  • For the proper demonstration of the Git, I'm creating a directory (folder) named learning-git. I am assuming this folder as my project folder where I will be working on.
    Folder Creation

  • 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


         arjun@techy:~/workspace/learning-git$ git init
         Initialized empty Git repository in /home/arjun/workspace/learning-git/.git/
Enter fullscreen mode Exit fullscreen mode
  • 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 file on Windows OS too.

  • Let's write some code on the file hello_world.c we recently created.
        #include  <stdio.h>

        int main()  {
            printf("Hello, World!");
            return  0;
        }
Enter fullscreen mode Exit fullscreen mode
  • 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


        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)
Enter fullscreen mode Exit fullscreen mode
  • We can observe that Git System is labelling 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. "


        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
Enter fullscreen mode Exit fullscreen mode
  • Let's check the status of the project I'm working on.

git status

        arjun@techy:~/workspace/learning-git$ git status
        On branch master
        nothing to commit, working tree clean
Enter fullscreen mode Exit fullscreen mode
  • Now I want to see what series of changes (log) I have made. Don't get intimidated, it's not mathematical log.

git log



        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.
Enter fullscreen mode Exit fullscreen mode
  • Looks like we've learned how to add files on the Git System. I am practising what I've learnt on projects. I hope you're doing the same.

I will be back with next part of the series.

You can explore more on my GitHub repository to feed your curiosity.

GitHub logo theArjun / cheatsheet

Contains cheatsheets and slides frequently used for development purposes.

Till then, happy coding :)

Top comments (0)