Git and GitHub: Part 1

Harsh
5 min readJul 31, 2020

What is Git?

Git is a free and open source version control system designed to handle projects with speed and efficiency.

A version control system is a system that records changes to a file over a period of time.

What is GitHub?

GitHub is a code hosting platform for collaboration and version control that lets you and others work together on projects.

We often face problems while sharing our code. To solve this problem, version control plays an important role. With the help of version control system(Git) you can post your code on a code hosting platform such as GitHub and from there your colleagues can review your code, make changes to it and can revert back to you.

We will cover more about GitHub in the upcoming parts. In this part, I will tell you some basic git commands.

Let’s GIT it!

Installing Git on your local host

Step 1 : Go to https://git-scm.com/downloads

Step 2 : Select the operating system you are currently working on. It will start the downloading it automatically.

Step 3: Click on the downloaded file to open it.

Step 4: Install the setup.

Once Git is installed on your local host, we are ready to go.

Checking Git Version

After installing Git, let’s check the version of Git installed on our local host using this command.

Syntax: git — version

If git is not installed successfully, command line will tell you that it is not recognized as a command.

git init

Now, using the cd(Change Directory) command, go to the directory where you want Git to track your files and folders. The git init command initializes an empty repository in the directory where Git will track your files and folders. Once the repository has been initialized, you will see a message -Initialized empty git repository in <your location>.

Syntax: git init

Repository is a workspace created by us to store files.

git status

After we have initialized our Git repository, let’s check the status of our repository using the git status command. Since we have done nothing in our repository, it will show no commits yet.

Syntax: git status

A commit is like a save or snapshot of your entire project

Master branch is the main branch of the git repository. Since we have not created any other branches so we are still on it.

Let’s first create a python file called test.py in our directory and then we will use git status and see what it shows.

After we have done git status, it shows us that the test.py file, which we have created in our directory, is untracked i.e. this file is not yet added to our repository. So let’s try to add this file onto our Git repository.

git add

git add command allows Git to track changes in our file and adds that file to the Git repository.

Now, let’s add test.py using the git add command into our Git repository so that Git can start tracking changes in our file.

Syntax : git add <name of the file>

Since we have added the file into our repository, let’s use the git status command and see what it shows us now.

You can see that the file which was previously untracked has now been added to our repository and it is showing a new file — test.py

git commit

After you commit changes in your file, it is important to do a git commit to keep the record of the change you have performed in your repository. It is a good habit to do a git commit after every change you make.

Syntax: git commit -m “commit message”

Commit message refers to the change(s) you have made in your repository.

Since we have added a file called test.py into our git repository, let’s make a git commit by using this command.

And now when you will use git status command, it will show that there is nothing to commit and everything is clean.

git log

To check your previous commits, you can use the command- git log. It will give you each and every detail about the commit i.e. date and time of the commit.

Syntax: git log

That’s all for this Part 1. I hope you all understood the basics of Git. If you have doubt(s) regarding this, you can leave a comment or contact me on LinkedIn.

Click here to refer to the next part of the blog.

--

--