Learning Git Basics

Mrigank Singh
4 min readOct 28, 2022

What is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Why learning Git is necessary?

Git is a must to have weapon in your tech arsenal. If you are working or planning to work in tech industry then learning git becomes a must. Although Git also provides us a GUI for windows users but chuck it, it has very less functionality. But question arises why Git is a must to learn. To be honest whether you are going to be working for a startup or a top firm or planning to start a tech startup, the code that you will be dealing with on daily basis will extensively use Git. So I will try to simplify the learning of Git from what I have learned. For any questions related to Git feel free to comment on article any question. Will be pleased to answer and who knows might be I will learn new things too.

Starting from Git Commit

To keep it simple, we can understand it as snapshot of our code changes (addition, deletion, update etc) every time we commit code. So in the next few steps I will be creating a file a.txt and then will commit it. Then I will made certain changes in the file and commit it on every step. To show you graphical representation of commits will use a specific command : git log — graph. By the way my bad, I started with git commit without telling what the main branch and the head commit is :P. The main branch on which no one dares to work except people who are born to play with fire and I am pretty much sure no sane person will do that. This branch is called main branch (earlier) or master branch (now-a-days). We will deep dive further in branching after learning few basic concepts. Lets begin with out first demo:

Boom an error but what is software engineering without errors and bugs. So what is it. Actually we forgot to initialise our git repository here. What we can use to initialise when we start any new project is:

git init

And boom we are ready for next step

Oh God!! Sheesh what we have now. Lets read and try to understand what it says. So it says that we need to add file using a command before committing it.

git add <filename>

or better what is more common is to add every file till now using a single command

git add .

Ignore the messages after successful git commit. They are just asking us to configure a username and password in case we want to upload to GitHub or Bitbucket. They are Internet hosting service for software development and version control using Git. It provides the distributed version control of Git plus access control, bug tracking, software feature requests, task management, continuous integration, and wikis for every project. We will cover about setting username and password and many other more secure ways to connect and commit to these Internet Hosting ways later on.

So lets come to git commit. The command actually is:

git commit -m "your message for commit here"

I think now it is much more clear. I will do some more commits (2) and see how the head and master branch looks like. The information about the commits can be seen in my commit message and here is an important lesson — Always type message with your commit about what they are to keep proper track.

Lets now see the log graph

So there are our full tracking our head is currently on master branch and the HEAD is on commit with message Added Profession. Just for an additional information the long alphanumeric code after commit is called the commitId. Hurray we have made our commits and learned about many commands.

I basically try to keep articles as short as I can as long articles are boring to read. So lets meet in next article where we should continue further.

Clap and Subscribe if you liked it.

--

--