Git and GitHub — Beginner’s Guide : A Hands-on Approach.

Aman Chopra
Nerd For Tech
Published in
9 min readJun 6, 2021

Being a Software Engineer, you probably have heard of these two terms Git and GitHub. Everyone in the programming world keep saying that you must know about Git and GitHub but no one actually gives the reason. Also what is the difference between Git and GitHub or are they same? Why should we learn it? What is the use of it? Well if you are also facing such kind of issues , no worry you will get all your doubts clear after reading this article.

But before jumping directly into the Git and GitHub we must know about Version Controlling System because that’s what Git is.

What is Version Control System ?

It is a system that records changes to a file or a set of files over time so that you can recall specific versions later.

It allows you to –

  • Revert the selected files back to a previous state,
  • Revert the entire project back to a previous state,
  • Compare changes over time,
  • See who has modified your code and when
  • Who introduced an issue and when.

Types of Version Control System :-

Central Version Control System
  1. Centralized Version Control System :-

In C-VCs, a client needs to get a local copy of source from server, do changes and commit those changes to C-VCS.

Working on branches is difficult and developers often faces merge conflicts. Also it does not provide offline access.

If server gets down, we can’t work anymore on it.

Distributed Version Control System

2. Distributed Version Control System :-

Here, each client can have local branch as well as have a complete history on it. Client needs to push the changes to branch which will then be pushed to server repository.

Working on branches is super easy, also we can create a copy of the repo in our local system so there is no issues like server down unlike CVCS.

What is Git ?

Git is a free Distributed Version Control System created by Linus Torvalds in 2005 to work with several developers on the Linux kernel for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development.

Why Git ?

  • Distributed Version Controlling System
  • Ease in collaboration
  • No more tension on loosing of old code
  • Live code and development code kept in one place
  • Easy to manage with large codebases
  • Distributed Development
Working of Git

What is GitHub ?

GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere. It offers the distributed version control and source code management functionality of Git, plus its own features.

It’s a place where you can find the most incredible open-source information, emerging technologies, features, and designs. It’s a place to learn and it’s a place to get involved.

Basically it is a remote server where you can store, manage, collaborate, contribute and share your codes or any type of work.

It is one of the largest hub for Open Source Software

⏰ Time for some Hands-On

Probably it is one of the most exciting part of learning any technology i.e. how to imply my theoretical knowledge in the real world scenario ? So without wasting time anymore lets see the practical implementation of Git and GitHub

How to install Git?

Go to the official website of Git and click on the desired OS option and it will automatically start downloading the software.

Now install it in your system by keeping all the options at default mode.

Now check whether it is installed properly or not using any terminal and check its version

Now we will setup configurations in the Git so that it can recognize us whenever we will make any contributions

Lets make an account in GitHub

Fill all the details properly and Signup.

Now Login to your GitHub account and lets start making repos :-

Click on the repository button and then New to create a new repository.

Repository :- It is a place where you have all your codes or kind of folder on server. It is a kind of folder related to one product. Changes are personal to that particular repository.

Click on Create Repository and 🔥 you just made your very first repo 🥳

After making a repo you may clone it in your local system so that you can start working on that or if you have already your folder in your local system you can still directly commit it to your repo.

Cloning :- It means you will create a copy of that remote repository in your local system with the same name and it will consists of all the preloaded code present in that remote repo.

git clone

git clone <url-of-remote-repo>

Now we will look how we can commit our files / code from the local system to the remote server.

git init

git init

This command will initialize a new, empty repo or it can be used to convert an existing, un-versioned project to Git repo.

Note :- No need to perform this step after cloning a remote repo as it will definitely consist of that folder.

git add

You can either use git add . command or git add <file-name>

Difference in both the command is the leading one will add all the files present in your folder but the trailing one will add only that particular file.

git commit

git commit -m “a meaningful message”

This command is used to commit the files to your remote repo with a meaningful message that you will write so that others can get to know what you have changed in that particular file.

git remote add origin <url>

You will get your URL by visiting your GitHub account in that repository section into which you want to make changes.

git push -u origin master

This command is used to push (send) the code from your local system to your remote repository.

Hurrah!! 🎉🎉 You just made your first commit in your GitHub. Go back to your GitHub account and refresh that repository page you will find all your pushed files.

Now you will be thinking that its great that I have successfully made my first commit but what if my friends also want to commit on that same repo. Come lets learn this together 😉

Fork the repo :-

It means that whoever will click on that fork button on the desired repo, the replica of that repository will be created in your GitHub account and now you can clone that repository (present in your account) to your local system to make changes or add new features.

It is always recommend that firstly you made changes to your forked repo and not directly to the original repo as it might downtime the original code.

Now that you have cloned that repo made all the recommend changes and successfully pushed the code in your repository, its time to make a Pull Request

Pull Request :-

After making changes and successfully pushing the code in your forked repository, you will see a button there named Compare & Pull Request which is used to open a pull request for that particular code. Opening a pull request means that now you are sending your changes to the original repository so that owner of that repo can review your code and then MERGE it if your code passes all the desired test cases.

git pull

This command is actually used to get all the additional changes made in your repository either by using GitHub GUI directly or by any pull request in your local system repo. So that in your local system also you can get the whole codebase which is present in your remote repository.

git log

This command is used to check all the history of commits with their timing and date. It also displays the message which you wrote while committing the file.

This is why we call Git as a Version Control System as it helps you to keep track of all your records of your commit files, deleted files, pull requests pushed, merged etc.

Branching

Git branching is the strategy or systematic procedure of creating the branch and follow that up for merging that with the main copy of the main branch of the codebase. Before getting into the Git branch, Let’s see why we need a branch.

Basically, A branch is the isolated and independent line of developing the feature. Assume the middle line as the master branch where the code is stable and updated. Then, assume a developer-1 is assigned to develop Feature — 1. So, Developer-1 is cutting a branch from the master branch which is indicated in the above diagram as in Magenta color. And, Developer-2 is assigned to develop Feature-2 and he is cutting a branch from the master branch. And, that is indicated as in Blue color.

Let’s assume the codebase is the set of four files called File-1, File-2, File-3, and File-4. So, when Developer-1 is taking the branch from master to develop feature-1 (assume File-1 and File-3 are going to be changed for the development). So, the developer can safely commit his changes on both files into the master branch. Vice versa, When Developer-2 is taking the branch from master to develop feature-2 (assume File-2 and File-4 are going to be changed for the development).

Unlike other Version Control system, Branching in GIT is logically copying the codebase and when it is getting merged to master branch, the only snapshot of the changes is appended from the feature branch to the master branch. But in other Version Control System like SVN, Branches are literally copied while cutting the branch and replaced while merging with the master branch.

Conclusion :-

But this was just the basics of Git and GitHub required to make contributions in any Projects but I strongly encourage you all to read more related articles on Git and GitHub to explore more functionalities of Git and GitHub

Happy Coding !!

--

--

Aman Chopra
Nerd For Tech

DevRel - Technical Writer | Product Builder | Cloud and DevOps Evangelist