Basic Git & GitHub for DevOps Engineers.

Table of contents
- What is Git?
- What is GitHub?
- What is Git and why is it important?
- Features of Git
- What is the difference Between Main Branch and Master Branch?
- What is Version Control? How many types of version controls do we have?
- Why do we use distributed version control over centralized version control?
- How do you create a new repository on GitHub?
- What is the difference between local & remote repositories? How to connect local to remote?
- Install git on your computer
- Task 1: Create a new repository on GitHub
- Create a new repository name DevOps_batch_3
- Clone it to your local machine
- Make some changes to a file in the repository
- Commit them to the repository
- Push the changes back to the repository on GitHub
- Set your user name and email address, which will be associated with your commits.
- Create a repository named "Devops" on GitHub.
- Connect your local repository to the repository on GitHub.
- Create a new file in Devops/Git/Day-02.txt & add some content to it.
- Push your local commits to the repository on GitHub.

What is Git?
Git is a version control system that allows you to track changes to files and coordinate work on those files among multiple people. It is commonly used for software development, but it can be used to track changes to any set of files.
With Git, you can keep a record of who made changes to what part of a file, and you can revert to earlier versions of the file if needed. Git also makes it easy to collaborate with others, as you can share changes and merge the changes made by different people into a single version of a file.
What is GitHub?
GitHub is a web-based platform that provides hosting for version control using Git. It is a subsidiary of Microsoft, and it offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its features. GitHub is a very popular platform for developers to share and collaborate on projects, and it is also used for hosting open-source projects.
What is Git and why is it important?
Git is used to source code management. It is a free and open-source version control system that is used to track changes in the source code and enable multiple developers to work together on non-linear development.
It is also a local machine that is used to make some changes and, push and pull the repo into and from the Remote repository.
It is important because it is allowing to work collaboratively. Software development projects usually require many people to work together. Git provides developers with a systematic way of doing that. Thus, the developers focus on the project instead of extensive communication sessions between the other developers.
Some of the reasons that make Git the preferred one are:
Speed
Scalability
Being free and open source
Features of Git
Tracks history
Free and open source
Supports non-linear development
Creates backups
Scalable
Supports collaboration
Branching is easier
Distributed development
What is the difference Between Main Branch and Master Branch?
A branch is essentially a unique set of code changes with a unique name. There are no inherent technical differences between the main and master branches. Main or master is the default branch when you create a repository. GitHub now uses main as its default branch while others still use master.
The one where all changes eventually get merged back into is called master. This is the official working version of your project. The master branch is deployable. It is your production code, ready to roll out into the world. The master branch is meant to be stable, and it is the social contract of open-source software to never, ever push anything to the master that is not tested, or that breaks the build. The entire reason GitHub works is that it is always safe to work from the master.
What is Version Control? How many types of version controls do we have?
Version control is a system that tracks changes to a file or set of files over time so that you can recall specific versions later. It allows you to revert files to a previous state, revert the entire project to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.
There are two main types of version control systems: centralized version control systems and distributed version control systems.
A centralized version control system (CVCS) uses a central server to store all the versions of a project's files. Developers "check out" files from the central server, make changes, and then "check-in" the updated files. Examples of CVCS include Subversion and Perforce.
A distributed version control system (DVCS) allows developers to "clone" an entire repository, including the entire version history of the project. This means that they have a complete local copy of the repository, including all branches and past versions. Developers can work independently and then later merge their changes back into the main repository. Examples of DVCS include Git, Mercurial, and Darcs.
Why do we use distributed version control over centralized version control?
Better collaboration: In a DVCS, every developer has a full copy of the repository, including the entire history of all changes. This makes it easier for developers to work together, as they don't have to constantly communicate with a central server to commit their changes or to see the changes made by others.
Improved speed: Because developers have a local copy of the repository, they can commit their changes and perform other version control actions faster, as they don't have to communicate with a central server.
Greater flexibility: With a DVCS, developers can work offline and commit their changes later when they do have an internet connection. They can also choose to share their changes with only a subset of the team, rather than pushing all of their changes to a central server.
Enhanced 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.
Overall, the decentralized nature of a DVCS allows for greater collaboration, flexibility, and security, making it a popular choice for many teams.
How do you create a new repository on GitHub?
Go to Github.com and sign in to your account.
In the right upper corner, there is a + sign for creating a new repository.
Click on the new repository
Enter the name of the repository
What is the difference between local & remote repositories? How to connect local to remote?
The local repository is on our local computer. Git local repository is the one on which we will make local changes.
A git remote repository is hosted on the server and it will be accessible to everyone.
A git remote command is used to make a remote connection i.e. connecting to Git local repository and Github remote repository.
git remote -v #to check push url
git remote origin main/master #to upload local repository content to a remote repository
Install git on your computer
sudo apt-get update #to update the machine
sudo apt-get install git #to install the git on your machine
git --version #to view the version of installed git
Task 1: Create a new repository on GitHub
Create a new repository name DevOps_batch_3
Clone it to your local machine
git clone url #to clone github repository into local machine
Make some changes to a file in the repository
sudo git add . #to add all the files
Commit them to the repository
git commit -m "Commit Message" #to commit into the repository
Push the changes back to the repository on GitHub
git remote -v #to check push url
git remote origin main/master #to upload local repository content to a remote repository
Set your user name and email address, which will be associated with your commits.
Create a repository named "Devops" on GitHub.
Connect your local repository to the repository on GitHub.
Create a new file in Devops/Git/Day-02.txt & add some content to it.
Push your local commits to the repository on GitHub.
Thank you for reading :)
Priyanka Varshney
Thank you for reading :)
Priyanka Varshney
Subscribe to my newsletter
Read articles from priyanka varshney directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

priyanka varshney
priyanka varshney
๐ Hello, and welcome to my DevOps journey! ๐ I am Priyanka Varshney,๐ ๏ธ As an aspiring DevOps engineer, I'm all about bridging the gap between development and operations, making software delivery seamless and efficient. ๐ป๐ง On this Hashnode blog, I'll be sharing my learnings, experiences and adventures as I dive deep into the world of continuous integration, automation, and cloud technologies. โ๏ธโ๏ธ Let's connect, learn, and grow as a vibrant DevOps community. Follow my Hashnode blog, and let's embrace the DevOps adventure together! ๐ค๐