Introduction
Hi Friends, How are you? I am Parimal Pradhan, Today I am going to explain Git ad Github.
What is Git?
Git is a version control tool that is used by developers for developing applications. It is installed on the local machine. Git is the most commonly used version control system. Git keeps track of the files you have edited so, if we want the previous code again we can revert it. once the code is done developer pushes the code into the central repository called Github. central repository can be Github, GitLab, or Bitbucket.
What is GitHub?
GitHub is a cloud-based hosting service centralized repository where all project source code is stored. Developers can pull the updated code from GitHub to the local machine where git is installed and start their work.
What is Version Control? How many types of version controls do we have?
The version control system keeps track of the work that we have done. It means which file is edited, and who is edited when it is edited. With the help of version control if one code is not working properly so we can revert it.
There are main two types of version control systems Centralized Version Control systems (CVCS) and Distributed Version Control systems (DVCS).
Centralized Version Control System(CVCS)
Let's understand the Centralized Version Control System(CVS).
In the case of a centralized version control system Developer has to write the code into the central repository. In the case of CVCS you don't keep local copy of your project and you have to connect with a central repository when you working. The drawback of CVCS is if something happened to the Central server then you don't have backup.
All Operations execute on the remote machine.
Always should have internet access.
Distributed Version Control System(DVCS)
In the case of DVCS, you don't need to connect always to a central repository. Just you need internet access while pulling the code and pushing the code. Developers just pull the code from the central repository to their local machine where it is installed. So in DVCS, each developer has a copy of the project. So if anything happens to the central repository they will have a backup on the local machine.
Why do we use distributed version control over centralized version control?
CVCS | DVCS |
Centralized version control system | Distributed version control system |
Must be connected to the internet | Can work locally, offline |
Each user has only a working copy | Each user has a full copy of a repository |
Branching and merging are time-consuming | Easy to fork, branch and merge |
Git Installation
We are going to install git on Ubuntu. Follow the below commands:
sudo apt update
sudo apt install git
which git
git --version
For Windows users you can visit https://gitforwindows.org/
Github
Now we will create a new repository on the GitHub account then we will clone it to the git local system. First, you need to create a GitHub account. once the account is created follow the below steps.
Click on the new repository
Once you click on New Repository New page will open like the one below. Enter the repository name as I entered. then click on create a Repository.
Now our repository is created on GitHub. Now use the git clone command to clone the central repository to the local machine repository.
Now go to the local repository using the cd command and use the git init command to initialize the git repository. you can see the git repository using ls -la
Now create 2 files using the touch command. then check the status of files using the git status command. Now use the command git add. to add files from the working area to the staging area.
Now check the again status with the git status command.Now commit the files using git commit -m "Followed by the message".
Now changes have been done and now it's time to push all our work into a central repository.
After using the git push origin main command our local work would be submitted into the central repository called Github. You can see the below image.
Thank You for reading this blog
Parimal Pradhan
You can follow me on LinkedIn for my daily updates:- linkedin.com/in/parimal-pradhan-b62021168
Great initiative by the #trainwithshubham community. Thank you Shubham Londhe