Sharply

loading...
Cover image for A beginner introduction to Git - A version control system.

A beginner introduction to Git - A version control system.

Franklin Okolie
A Frontend Engineer focused on building aesthetically pleasing user interfaces with a focus on user experience and user interactions.
・6 min read

People lose important information on files, lose track on them and end up regretting why they never had copy or another version of that document, this happens all over the world in all careers. It takes a lot to keep files in check and more importantly when multiple people are using the same files such as editing it, how would you be able to keep track of the original copy if everyone is writing on it? This was a real-life problem that further extended into Software Engineering.

In this article, I will be introducing you to Git a powerful and popular version control tool built by Linus Tovarlds and was released for initailly released on April 7, 2005, it was quickly adopted by individuals and companies for their day to day activity.

Prerequisite

  • Basic knowledge on command line.
  • Basic knowledge on HTML & CSS.

What is Git?

Git is a version control system/tool for tracking changes in files, usually used for organizing work among software developers collaboratively developing source code during software development.

With Git, many developers working on a software application can make changes from anywhere in the world at any time, and Git would be able to track the changes in the file, Git also give developers the ability to make another version or copy of a file and makes changes to that file without having to touch or tamper with the original copy.

Why do you need Git?

In almost every professional environment where products are built and shipped daily from the smallest startup to Fortune 500 companies, Git is been used for effective development.

In the open source environment where the software is developed by thousands of people all over the world, there is definitely a need for it.

When a software application is been built, many people are working on it at the same time, so there is a need to track where those changes are coming from, who is effecting those changes e.t.c, with Git you can:

  • Track changes on a file.
  • Make multiple versions of a file.
  • Reverse changes made on a file.
  • Work effectively through collaborations.

As budding developer, it is advisable to learn how to work with Git as early as possible for effective work.

Installing and setting up Git.

Git can work on any operating system of any kind, it is very felxible.

To install Git, you need to visit their website here and download it for your operating system, after that you need to configure and set git for your local environment.

To configure Git, you need to open your command line and type the following command, remember to replace the sample name and email with yours.

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

This will configure and set your username and email for Git to be able to track changes locally on your computer and also know who made those changes.

How to use Git.

To use Git, you need to first set up a folder with files which you want to track using Git and give it any name of your choice. I am doing to create one called mine with learning-git

This is how my folder look like for a start :
Starting Folder

From the above image, I have created a folder which I want to track changes on it's files using Git.

Now if I am to make changes to the folder and I want Git to track it, I have to initialized a Git repository on my local machine. Does that sound complex? Well it is not, it can be done through a simple command.
git init

initailized Git

From the screenshot above I used the intergrated terminal in my code editor(VScode) to run the command git init, Git will go ahead and initialize a repository for the folder and start tracking changes on the folder and any files of the folder.

Now that the folder is been tracked by Git, any changes on it will be indicated, and I am going to create a new file named index.html inside the folder and let see if Git will be able to track it.

Git Tracking Changes

And Git was able to track a change in the file and showed an indication in my code editor, you can notice the visible color on the file; a green color, this is Git way of telling us that a new file has been added.

Note: The colors of indication varies on code editor and themes used in the code editor, I am using VScode and the SynthWave theme.

Staging and Commiting Files using Git.

Now that Git has tracked the new file, the new file or changes will not added to the Git repository except it is given permission, and this process is called Staging and Commiting Changes.

With Git you can stage new changes using the command git add <file name> in the case of this tutorial, the file name is index.html, the command is :

git add index.html

Staged the file

This will tell Git to add the file and it changes to the staging environment, the staging envoironment itself is a way you tell Git that you are aware of the changes but you are not adding the new changes yet.

To add the new changes or commit it, Git also provides a command git commit -m <comment for the changes>.

Commenting your changes provides information on a certain change you made to a file, this will provide some details when the file changes is been tracked and viewed by other people.

`git commit -m "Added a new file"

Added New File

From the screenshot above, Git has added the new file by permission to the Git repository. Git will also track changes on this file too.

I am going to add a paragraph to the HTML content and let see if Git will track the changes on this file or not.

Tracked Changes

You can notice a change in color on the file name from white to purple. This is Git indicating that there is a change in the file and you have to give Git permission to add the changes to the repository by staging and commiting it as I have done above.

Note: The colors of indication varies on code editor and themes used in the code editor, I am using VScode and the SynthWave theme.

Git Service Providers

From the beginning of this article up until now, I have explained it and how it is used locally, I also want to explain some common service that use Git to provide services so we can store our files and repositories on a remote server as opposed on storing them locally on our computer.

Git service providers replicate all that happens locally on your machine with Git, but now you can see any file or folder and their changes visually on a web application or software, it also helps in preserving Git repository as local machines can get damaged or stolen and this will cause developers losing their files.

With Git and their service providers you can use Git locally and connect it to the remote repository with both working in sync.

Below are some examples on some of the best and most popular Git Service Providers:

More resources on Git

Below are some resources carefully picked by me to further your understanding of Git and how to use it with any of it's service provider.

Conclusion

Thanks for reading, I really hope you got valued from this article, if you do, don't forget to like and share so it help others too.

Do you have any questions concerning Go, Javascript, Tailwind, Open-source, Blockchain or are you a new developer looking for a welcoming community? You can reach the Sharply community here.

Discussion (0)