Day 8: Understanding Git & GitHub

ยท

6 min read

This is the Day 8 of #90DaysOfDevOps challenge that covers the most important topic of Development, DevOps Engineers, and most important this is the starting part of the CI/CD pipeline. But, before discussing Git and GitHub first we all need to know about Version Control System (VCS).

What is Version Control System (VCS)?

Suppose there are 4 persons (A, B, C, D)located in different cities or countries and they are working on the same project in the same team. A is the developer that is writing the code and each and every person is contributing to the project code by adding some functionalities, features etc by having separate branches that are merged after checking all the developer's code.

Version Control System is a kind of software that helps to manage or track the changes in source code by developers. Suppose a developer has added some new features and after some time it wasn't working properly so if we want to go back and omit the changes then here Version Control System comes that keeps the track of files by this we can simply omit the new changes.

There are three types of Version Control Systems:

1) Local Version Control System: It has a database that kept all the changes of files under RCS (Revision Control System) which is the most common tool under VCS. It keeps the difference between file in a special format on disk.

2) Centralised Version Control System: It has a single repository that is present globally and every developer can see this repository and commit to a single repository. By this, we can see what developers are committing and updating the code or any file in the repository. But the main problem of having a single repository is that suppose the central database has been corrupted then all that files will also be corrupted by this we can lose all the source files.

This problem is fixed in DVCS i.e Distributed Version Control System

3) Distributed Version Control System: It contains multiple repositories so that developers or a person have their own repository. In the DVCS if you had done a commit to the repository then the changes that you had committed will not be accessed by anyone unless you push to the central repository because the commit happens in your local repository. To make changes or to see changes in your central repository first commit the changes and then pushed them to a central repository.

Examples are Git, Mercurial, and Bazaar.

Now we have to understand Git and GitHub.

What is Git?

Git is an open-source popular version control system that helps to keep track of the changes in the repository, tracking who made the changes and who is collaborating. It was developed in 2005 by Linus Torvalds who created Linux but now Git is maintained by Junio Hamano.

But Why should we use Git?

  • 70-80% of developers are using it.

  • Globally developers can make collaborations all around the world.

  • Developers easily revert the changes.

  • Developers can see the full history of their commits.

Working of Git:

The heart of Git is a repository. By making the repository you can store the source code in a remote/central repository. Developers can clone the repository to your local machine so they can make changes in the source code and run it on the local system. Through staging and committing developers can keep an eye on changes in source code. Then, after committing the changes push the code to the remote repository. After finalizing every developer's source code merge it into a single source code.

To download Git: https://git-scm.com/downloads

After downloading open the terminal and execute the command :

git --version

OK !! We understand Git but what is GitHub?

What is GitHub?

GitHub is the platform where all developers all around the world make their code public and most of the big tech companies make their source code public so developers can add some features to it like Linux is open source, and we all can contribute to it. Git is not the same as GitHub but GitHub uses tools that use git and it is the largest host of source code in the world that is owned by Microsoft.

Go to the github.com Sign Up page and make your account.

After creating a GitHub account let's do some exercises:

1) Create a new repository on GitHub and clone it to your local machine.

The first page will look like this :

So, to create New Repository you will see on right top corner (+) icon click on it you will see 'New Repository'

After clicking on this, give the name of the repository then choose public if you want to show your repository to everyone, then create a repository.

Congo !!! You created your first repository.

After clicking create repository a new page will open that will give some commands to execute in the terminal. By creating the new folder on your system execute these commands under that folder. After executing .git folder will be generated that keeps track of all the changes of your repository.

After, executing the commands in the terminal (just copy and paste in the terminal). While executing these commands it will ask for a username and email, execute these commands:

git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"

After executing this it will ask for authentication to sign in to the browser and it will also ask for personal access token so for generating this go to your profile pic icon and click on settings, scroll down the page at last in the left you will see the developer settings. After clicking on Developer settings you will see Personal Access Tokens under this click on Tokens (Classic) then generate a new token and select all the checkboxes. After generating a new token you will get the token copy it and store it safely in your system once you will get to the next page you will never get the token. Copy this token and now your repository is available you can make any changes to the repository.

This is the look of your repository.

2) Now, add some files from your created folder that is on your local machine.

First, create file that will contain "This is the Day 8 of #90DaysOfDevOps Challenge". I created the challenge file.

To push back to the remote repository i.e on the central repository. First, you have to initialize the git repository by executing

git add .

. means present working directory which means add the file that is present in this directory.

Now we have to commit the changes to the local repository. The changes will now go to the staging area. For this we need to execute :

git commit -m "Challenge file"

-m means a message that what name of the commit you want to put in pushing to the repository.

To push to the central repository or remote repository you need to execute

git push

This command will push your created file from locally to you central repository that can see anybody.

Now when you refresh the repository page you will see that your file has been successfully pushed to the central repository.

So, this is all about today's Day 8 challenge. We will discuss more Git commands in the next blog. So, Stay Tuned !!

Follow me on Hashnode for more amazing Linux and DevOps blogs.

Connect me on Twitter !!

THANK YOU :)

ย