Git 101

Arjun AdhikariArjun Adhikari
3 min read

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 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

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.
#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
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. "

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
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
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.

0
Subscribe to my newsletter

Read articles from Arjun Adhikari directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Arjun Adhikari
Arjun Adhikari

I am a Django developer driven by a deep passion for coding and a relentless pursuit of problem-solving. Over the years, I've cultivated my skills in web development, specializing in crafting powerful and scalable applications using the Django framework. Every project is an exciting challenge for me, and I thrive on unraveling complex problems to create elegant and efficient solutions. My commitment to staying at the forefront of industry trends and technologies reflects my dedication to continuous learning. Whether it's building innovative features from scratch or optimizing existing code, my enthusiasm for coding is at the core of everything I do. I find joy in the journey of creating impactful and user-friendly applications, leveraging the full potential of Django in the process.