What is Git?
Git is a version-control system used for tracking changes in computer files.
It helps you to keep track of all the changes made to a project's files, so if something goes wrong, you can easily go back to an earlier version.
It is primarily used for source-code management in software development
It helps in coordinating work on those files among multiple people.
Why do we need Git as a DevOps Engineer?
As DevOps engineers, we need git because it helps in lots of important things:
Keeping Track of Changes: It helps in keeping track of changes made to our code and configurations over time.
Working Together Smoothly: It makes it easy for different teams to work together on the same projects without causing conflict.
Making Sure Things Work: It works hand-in-hand with the tools that automatically test and deploy software. It also helps to catch problems early and make sure everything runs smoothly.
Fixing Mistakes: If something goes wrong, it allows you to go back to an earlier version of your work, like hitting an undo button.
Knowing What's Going On: It keeps a record of who changed what and when and helps to figure out what caused problems and how to fix them.
What is GitHub?
GitHub is an online platform built around Git, the version control system. It acts as a hosting service for software development projects that use Git for version control. Developers use GitHub to store their code repositories, collaborate with others, track issues and bugs, and manage project documentation.
What is version control?
Version control is a system that tracks changes to files over time.
It allows us to record different versions of our files. It keeps track of who made changes, and reverts to previous versions if needed.
It is useful in software development and other collaborative projects where multiple people are working on the same files, as it helps in maintaining transparency, effective management of changes, and ensuring clear understanding and coordination among team members.
How many types of version control?
There are two types of version control
(i) Centralized Version Control Systems (CVCS):
In this type, there's one big central server that stores all the files and their versions. When we want to work on something, we have to get the files from this central server which is also known as "update". We make changes and when we are done with our work we put it back there which is known as "commit". The developers can commit directly to the main branch.
(ii) Distributed Version Control Systems (DVCS):
In this type, Git has a remote repository which is stored on a server, and a local repository which is stored on each developer's computer. This means that the code is not just stored in a central server, but the full copy of the code is present in all the developers’ computers. Git is a Distributed Version Control System since the code is present in every developer’s computer.
Why do we use distributed version control over centralized version control?
Distributed version control systems provide greater flexibility, and backup plans, and work faster compared to centralized version control systems. It makes it more suitable for modern software development workflows, especially in distributed and collaborative environments.
What was the problem before version control?
Before version control, we have to do versioning manually.
At that time team collaboration was a time-consuming and hectic task
We don't get easy access to previous versions multiple versions take a lot of space.
Advantages of using version control
It helps in doing versioning automatic .
By using it Team Collaboration is simple Easy
It gives access to previous versions
It only modified code which is stored across different versions, hence saves storage.
Q. Create a new repository on GitHub and clone it to your local machine.
-> Open github.com and click on the "+" sign at the right corner which means create new after that click on the create new repository.
-> You can see this type of interface. you can give a name to your repository whatever you want
-> After that click on Create repository
-> You can see this type of interface after creating the repository
-> For cloning the repo to our local system we can copy the HTTPS address. We use the command git clone
to clone the repo.
git init
: It will initialize the git repo in our local system.
git add
: It will add the file to the staging area.
git commit -m "first commit
: It will commit the code with the message first commit.
git branch -M main
: It will push to the branch we want.
git remote add origin
https://github.com/vishalkumar-vk/tasks.git
: it will connect to our local system repository on GitHub.
git push -u origin main
: It will used for push to the repository.
-> We can see it is successfully pushed to the repository on our local machine.
Summary:
In this blog, we see the basics of Git and GitHub. We also learned about version control and saw how to create a repo and clone it. Git plays an important role in DevOps engineer life for doing versioning automation, keeping track of changes, and updates, and fixing mistakes.