Table of contents
Imagine you are working on a document and you make some changes to it. You save the document with a different name (like adding a "_v2" at the end of the file name) so you can go back to the original document if needed. But, what if you make more changes and then decide that the previous version was better? It would be tedious to manually compare the two versions and copy the changes from one to the other. This is where a VCS comes in handy.
Version Control System
Version Control System (VCS) is a software tool that helps us manage changes to projects over time. It tracks the history of the project, allowing it to compare different versions and revert to earlier versions if necessary.
In Layman's terms, A VCS allows you to keep track of changes made to a file or a set of files over time.
VCSs allow for collaboration among multiple people working on the same project. Different users can work on different parts of the project simultaneously and merge their changes together into a single version.
There are two types of VCS: Distributed Version Control and Centralised Version Control.
Distributed Version Control System (DVCS)
Distributed VCSs create local copies of the repository on each user's computer, allowing them to work offline and merge changes back to the central repository later.
Users create a local copy of the repository and can work offline, committing changes to their local repository. They can then synchronize their changes with other repositories by pushing and pulling changes between them.
Examples of DVCS include Git, Mercurial, and Bitbucket.
Centralized Version Control (CVCS)
Centralized VCSs have a central repository that all users access and make changes to.
Users connect to this central repository to check out files and make changes. When a user makes changes, they commit their changes back to the central repository. The central repository manages conflicts between changes made by different users and stores a complete version history of the project.
Examples of CVCS include Apache Subversion (SVN) and Microsoft Team Foundation Server (TFS), Perforce.
Why DVCS or CVCS?
DVCS and CVCS can be compared to cooking a meal for a large family gathering.
CVCS is like a centralized kitchen where everyone has to cook their food on the same stove. This can lead to chaos in the kitchen, with people bumping into each other and fighting over stove space.
DVCS, on the other hand, is like a potluck dinner where everyone brings their own dish. Each person can work on their own dish at their own pace and in their own kitchen, without worrying about getting in each other's way.
While the centralized kitchen may be easier to manage and organize, the potluck dinner allows for more flexibility and creativity. Plus, everyone gets to enjoy a wider variety of dishes!
DVCS offers several benefits over CVCS, including:
Better collaboration: DVCS allows for easier collaboration among team members, as each member has their repository and can work independently. Changes can be easily shared and merged across repositories.
Flexibility: With a local repository, users can work offline without worrying about connectivity issues. This is particularly useful for developers who need to work on the go or in remote locations.
Better branching and merging: DVCS systems typically offer more powerful branching and merging capabilities, allowing for complex workflows and easier collaboration.
Security: In a DVCS, the repository history is stored on multiple servers and computers, which makes it more resistant to data loss. If the central server in a CVCS goes down or the repository becomes corrupted, it can be difficult to recover the lost data.
Git and GitHub
Git
Git is a distributed version control system (DVCS). Git allows multiple developers to work on the same codebase simultaneously, without conflicts or overwriting each other's changes. It keeps a complete history of all changes made to the codebase, making it easy to track and revert to previous versions of the code if necessary.
Git also allows for branching and merging, which enables developers to work on different features or versions of the code in parallel and then combine their changes when ready.
GitHub
GitHub is a web-based platform that provides hosting for Git repositories. It allows developers to store, share, and collaborate on code with other developers. GitHub is used by millions of developers and organizations to host their code and manage their development projects.
GitHub provides a variety of features, including Repositories, Collaboration, Integrations, Social features, and Community.
Tasks
Task 1: Install Git on your computer
To install Git on your computer, please follow this manual by Atlassian Install Git.
Task 2: Create a free account on GitHub
To create your account on GitHub, you can sign up on GitHub SignUp. To know more about the creation of an account on GitHub, you can follow this guide: Signing up for a new GitHub account.
Exercises
Exercise 1: Create a new repository on GitHub and clone it to your local machine
Go to your GitHub account, and click on your Profile Icon. From there select "Your Repositories" > " New".
Once the window opens, type the name as required of your new repository. Here I am naming my repository name as "NewGitHubRepository". And then click on Create Repository.
Voila! You have created a new repository in your GitHub account!
To clone this repository to my local machine, Select the "Code" option, which is in the green color dialog box and copy the HTTPS link from there.
Then, open Git in your system and go to your preferred directory. The command used for cloning a git repository is:
git clone https://github.com/thesnehasuresh/NewGitHubRepository.git
The Git Repo is cloned!!
Exercise 2: Make some changes to a file in the repository and commit them to the repository using Git.
Let us create a file named NewFile.txt and say "Hi, This is my new File!".
So now to commit the file to the repository, first we need to add the file to the staging area, and then commit it.
git add 'Filename'
git commit -m 'Commit_Message'
The file that was created has been committed successfully to the local repository!
Exercise 3: Push the changes back to the repository on GitHub
To push the changes to the GitHub repository, we use the command:
git push -u -f origin
You are asked for your GitHub username:
Enter your GitHub username. Once you are asked Password, generate the token ( follow this link for Creating a personal access token) and paste the token. Make sure you save the token in your local for access as and when required.
Voila! The file is now pushed to GitHub, which can be verified from the below image:
In the next blog, I will deep dive into Git and GitHub.
To help me improve my blog and correct my mistakes, I am available on LinkedIn as Sneha K S. Do reach me and I am open to suggestions and corrections.
#Day8 #90DaysofDevops