Introduction to Git and GitHub for BEGINNERS

2021.02.24

This is the first article in the series of "Introduction to GIT and GitHub for BEGINNERS".  It may not make sense in the first place as to why we should learn Git commands and those buzz words around Git and GitHub like repository, staging, commits, etc, but once we know the concept and the general workflow; it will never be a mystery anymore and will surely become our daily friend. Git and GitHub are not just for developers, can be used by NORMAL USERS TOO!!!

Glossary

Open-Source:-Referred to open software designed to be publicly accessible, anyone can see, modify, and distribute the source code as they see fit.

Repositories:-Repositories are like a folder or a place that will contain all our code files.

Commit:-  To save the changes.

What are Git and GitHub?

People often misunderstand the meaning of Git and GitHub as the same but they are not at all SAME!

Git:- " It is an open-source system/tool; also known as Distributed Version Control System". It is a way that allows us to track changes to our files, documents, folders, and of course our codebase.

For a 5-year-old kid, " Git is like a notebook, which automatically keeps track of all the changes to your files and allows us to remove a particular change, revert or rollback to any change" This helps us to answer questions like what changes we did, where we did, who did, track bugs.

GitHub:- " It is an online hosting service which hosts Git repositories and allows us to perform CRUD operations on them".

For a 5-year-old kid,"  GitHub is like a  Public container/box which holds the notebook ( git repositories). Because it is public an individual's notebooks(git repositories) can be seen by anyone "

 

Why we should use Git and Github?

There can be many reasons but from the Beginners' perspective perhaps the following are the most important:-

Git

  • Create something -> modify -> remodify -> mistakes -> recover!!!

Let's say we are writing a book, with time we will add more content if we want to see all the changes we made with time ( commit) we can easily see those changes in comparison to the current one using git; one day we realize we want to go back to the content which was written one week before, Because of its tracking ability, git enables us to go back or revert to a week before, we can also choose exclusively which changes to keep and which changes not to be kept.

  • Sharing, merging changes from others.

Let's say our friend wants to help us in writing the book, so in such a case git allows us to branch ( give a copy of the book), our friend will make the changes, and then we can either reject those changes or accept those changes. Also helps us to know where the changes were made when it was made

GitHub

  • Online, central place to store git repositories.

GitHub is a hosting service that allows us to store our git repositories (a copy of changes local to our computer) on GitHub under our GitHub account and make them public repositories and then can access it from any other computer or any other GitHub account.

There are many other hosting services like BitBucket, GitLab, SourceForge, etc.

  • Provides a GUI to see those changes, manage the repository, share with others.

It gives a simple and interactive Graphical user interface to manage our repositories efficiently, provides a platform for other users to share repositories, sees each other's repositories, improves the repositories by forking, cloning, and merging pull request ( will be discussed later)

NOTE:- There are many more compelling reasons but for a new user these are the most relevant.

When and Where can we use Git and GitHub?

Git

There is no time as to when we should use Git, but a good practice is to start using it whenever we are starting a new project to track our changes right from the beginning of our project. Git is used for initializing a local git repository on our computer, without a local repository git cannot track changes.

GitHub

A moment of truth, behind the scenes even Github is using Git as its version control system.GitHub is an online service that is accessed over the internet. We can use GitHub either to store our local repository or directly create a repository on GitHub.

Since GUI is interactive and easy to understand let's start with creating an account and repository on GitHub

Creating an Account and Repository on GitHub

  1. To create an account  go to -> https://github.com/join
  2. Near the upper right corner Click on "+" to create a new repository, select a name that is unique and make it public for now.
  3. [optional] you can add a description for your repository.
  4. Leave other options as it is and click on create a repository.

Creating a Readme.md and committing changes.

  1. Under the repository, click on Creating a new file.
  2. Name the file as README.md and add some content and commit it (save it).
  3. Give a meaningful name to your commit ( giving meaningful names to commit is very important to revert and track changes)
  4. [ optionally] you can add a description for your commit too.
  5. Click on README.md to see its contents.
  6. let's edit this file by clicking on the pen icon.

Note:- By default when we create a repository we make every change in "main" branch. Think of the main branch as a primary stem of the tree that holds all the changes. There can be other branches too similar to a tree but for now, we should concentrate on "the main branch"

Checking the commits and changes

  1. Go to commits.
  2. you can see the various commits ( in our case there are 2 commits)
  3. Click on any of the commits.
  4. The + shows these lines were added.
  5. let's make some more changes and commit again as 3rd commit.
  6. -  and red shows which lines were deleted and again + and green shows what were added.
  7. Additionally, We can also add comments to the changes by clicking on + for others and future reference.

In the next article, we shall learn in-depth about the Git tool, workflow, and its various commands. Till Then Happy Learning :)