Introduction

Hello Everyone!

Web developer tend to work on local development sites then just upload everything when they are done. This is fine when it’s just one person and the changes are small. But when we are dealing with more than one person working on a large project with lots of complicated components, that’s simply not feasible. That’s when we turn to something called “version control“.

Today I’ll be talking about an open source version control software called “Git“. This allows more than one person to safely work on the same project without interfering with each other. We will learn how to manage files and source code. We will use git to track changes and learn to write clear messages.

Outlines

  • Download GIT
  • Installation
  • Configuration
  • Help Command
  • Initialize GIT
  • GIT Commit
  • GIT LOG
  • Precautions
  • Conclusion

Description

Download GIT

First we need to download GIT from it’s original website. It will auto deduct the system you are using and will give you the regarding file. Now you just need to install the file. Do a closer look on the below picture.

GIT

Description

As you can see inside the above picture it deducted my system as I am working on windows. Or you can just click the download option to select the system type.

Installation

Install it where ever you wanted to in your local machine. When it is installed open it, the below window will appear in front of you. Take a closer look.

GIT

Description

This is a command bar of git. This is where we will write our commands. Now lets do some things.

Write “which git” command in it. It will tell you  the path of our git if it exists and if we write “git –version“, it will tell us which version of git we are using.

GIT

We can see our directory by giving the command “dir” in windows while “ls -la” for “UNIX“. We just succeeded to install git on windows.

 

Configuration

There are three places where git stores it’s configuration.

  • System Level

The first and largest is system level configuration. This auto apply to every user of this system. We don’t need to use it often, I just wanted to tell you that it exists. On UNIX it is inside a file “/etc/gitconfig“. It will be inside the same file in windows, but only stored on different place.

  • User Level

Now the most important place is this user level configuration. It is for single user which is sitting on a single machine. On UNIX it will be inside your home directory in “~/.gitconfig“, while in windows it will be inside your user directory which is home directory “$HOME\.gitconfig“.

Now I am configuring user.name and user.email. The commands I shall use (git config –global user.name “Abdul Hadi”). Same for the email git config –global user.email “example@domain.com”

  • Project Level

The third place where we can do configuration is by project by project base. So in a single project we will apply, which is inside to that project only.

Description

How to configure it? There is a command “git config –system” it will be same for all the systems on the basis of system level configuration.

On User level it will be “git config –global” and if there is no modifier it will be system level configuration “git config“. When you configure name and email by you can check the list by writing another command “ls -la”. Or you can even view them separately, the commands are shown in the below images.

GIT

In the above picture in configured user.name with My name. As you can see the command I used for this purpose.

GIT

In the above picture in configured user.email with a random example. As you can see the command I used for this purpose.

GIT

This is the list I got by writing ls -la command

An other important configuration I want to tell you that the type of file need to configure. We need to tell git which text editor we will be using. This allows git to open up  the text that need editing in this editor by default. The command we needed for this is (git config –global core.editor “name of the editor you want to use“).

GIT

As you can see My command to add the file type I shall use from my windows.

The other important thing we need to configure is the color so that the text will appear properly.

 

Help Command

This am important command inside the git, it helps us to know about a list of commands. “git help” command will generate a list of all commands and you can just see the details of a specific command by writing “git help example“, place the name of command in the place of example and it will show you the detail. I recommend you to use these help pages when ever you get stuck or don’t know what to do, or you can even give us feed back so that we can help you.

GIT

As you can see in the above picture I gave the help command. It showed me a number of commands that are inside the library of git. You can use them when ever you need.

Initialize GIT

Once you configured git now you need to initialize it, to tell git start tracking things in this project. We will be doing this with another git command “git init”. It is a way to tell git that everything is ready now so start tracking. First to decide where to put the project. I placed it inside my documents folder and named it “first_git_project”. Now you need to go inside this project by command “cd Documents/first_git_project”. We are now inside our project folder.

GIT

This is where I need to do my git initialize by the command I told you earlier “git init”. By doing this git is only concerned by the things inside this file. Now all you know that our folder is empty, but when we go through command line and we give a command “ls -la”. This command will show all the hidden files present in it. Any file with a “.” in front of it will be hidden.

GIT

As you can see the .git directory, it is a created  by init command. It is the place where git store all of it’s tracking information. Let’s see what is inside this directory by giving a command “ls -la .git” it will show the below image.

GIT

Don’t mess with these files, the only file that you need to be the “config” file. This is our project level configuration. Everything you do will be stored in this top level directory. Now we are ready to make change and see git tracks it or not. I just created a text file and placed it inside my first_git_project. Now I shall go to the command line to tell git that track the changes I have made by “git add.” command. Now I shall commit this change by a command (git commit -m “initial commit”) You can write any message but it should be specific. The put is shown below.

GIT Commit

In this command we commit what ever we added. There are few rules to do this.

  • It should be small and short summery (less then 50 characters).
  • Followed by a blank line.
  • Keep each line less then 72 characters.
  • Always write in present tense.
  • Be clear about the commit you write it should explain everything.

These are the most important points on the basis of which we commit the file.

So there are simple three steps that we shall be doing mostly all the times.

  1. Make Change
  2. Add Change
  3. Commit Change

This is the basic pattern that we follow.

GIT LOG

In this portion we will view our commit that we did earlier by the help of the command “git log”. Take a closer look on below image.

GIT

What we have here? As you can see it returned me the commit in a form of a code of yellow color, your’s might be different. We say it commit ID, each commit has it’s unique ID. It tells the author of that commit and the date of this commit. It told the author name due to my global configuration. In the end we got the message.

If we are dealing with multiple people working on it, so I just open the file and see the number of changes made by them. There are number of options by using the log, you can check them by giving the command “git help log”.

We can also limits the number of commits by giving the command “git log -n 1” or “git log -n 2”. We are just able to see the most recent 5 by the help of this.

We can also check the commits by giving a time duration. Take a look on the below picture.

GIT

As all you can see it showed two commits that I made since this date. Same we can view by writing until instead of since. WE can see commit by just giving the name of the author. Take a look on the below picture.

GIT

As you see in the above picture I gave the author command and it showed me the commit made by this author. We can also search by commit we wrote, it will show you git log –grep=”init”. The only thing you need to write a proper expression.

Precautions

Write the command properly other wise it will con work. Do mention the parent directory otherwise it will fail to work. Always fallow the sequences. Follow the pattern.

Conclusion

What we learned today? We learned how to download and install GIT. We learned different commands of git. We studied three basic steps while working with git. Make change, add change and commit that change. If something is missing or you didn’t understand do inform Me.