Sai Yerni Akhil Madabattula
Sai Yerni Akhil's Blog

Sai Yerni Akhil's Blog

Go, Git it! — Beginner’s guide to making your first commit.

Go, Git it! — Beginner’s guide to making your first commit.

Sai Yerni Akhil Madabattula's photo
Sai Yerni Akhil Madabattula
·Oct 4, 2019·

6 min read

Before getting to know what is Git, we need to know what are version control systems. They are the code management tools which allow us to maintain different versions of the code in a non-clumsy way. When I was starting to code and create websites I used to make copies of the folders like this —

Haha! it’s funnyHaha! it’s funny

It seemed okay then. But, When I have to deal with more and more complex projects I felt difficult to move on and often confused. But its when version control tools like Git looked like a saviour to me. Why? let’s check it out.

  • Cleaner project directories.

  • Ability to rollback.

  • Maintain different versions of the code (branches)

Git logoGit logo

Installing git isn’t a tedious task and you can find the detailed guide here.

So, while we are learning about git there are certain terms which are important that we understand and we come across them every time —

  • Repository
  • Commit
  • Branch

What is a repository?

A repository (or a repo) is a parent folder which the git tracks, which may be the directory which contains the project files. In case of a web app, the repository contains all the Html files documents, stylesheets and images which are used in the web app.

How to create a repository? Creating a repository is very easy, you can intialize an empty repository or turn an existing project into git repository or else move to the existing project repo and use the command *git init using git command line tool.*

initializing a repositoryinitializing a repository

Now, What is a commit?

A commit is a checkpoint. Let us say you have initially created a web app and then made changes to the initial version. Now you’ve made a blunder and messed with the project and wanted to revert to the initial version, with the help of a commit. Commits are checkpoints, as mentioned before and we can come back to it.

How to make commits? Here it is, this is how we make a commit — git commit Before we make a commit we need to stage the changes. Staging changes helps us to commit all the files at once without fail. We can stage all the files at once or we can a single file using — git add . or git add <filename> while comitting we need to specify a commit which briefly describes the changes. So we generally use a message flag -m directly in the command- git commit -m “<commit message>” each commit i.e., each checkpoints has it own id.

The initial version of file random.txtThe initial version of file random.txt

Staging and committing the files in the repositoryStaging and committing the files in the repository

Now making a second commit

Staging and making a second commitStaging and making a second commit

How do we revert? We can revert using the commit specifying the commit ID git checkout <commit-id>

When we go on with the software development we need have a look at the commits. For that we’ll be using the command — *git log which is a pretty useful command.*

What are the branches?

When we want to test new features in our software without actually disturbing the original version. We use branches for that very reason.

How do we create branches? Branches are creating by using same command we used in earlier by using a -b flag. git checkout -b <new-branch-name>

Now have a look at the same file in two distinct branches and you’ll clearly know why we use branches —

How to delete a branch? A branch can be deleted by specifying a -d flag git checkout -d <branch-name>

Now that we are clear with the terms used in Git. In the next post, we’ll learn how to host it on the internet.

Do share and suggest some improvements.

Share this