Git & GitHub

Basic Git & GitHub for DevOps Engineers.
What is Git?
Git is a version control system that monitors code changes, enabling collaboration among multiple users. It allows you to save various versions of your project, work offline, and easily merge changes from different contributors.
What is GitHub?
GitHub is a web-based platform for hosting and managing Git repositories, providing a collaborative environment for developers to store, share, and work on code together. With GitHub, you can:
Host Repositories: Store your Git projects online, making them accessible from anywhere.
Collaborate: Work with others through features like pull requests, code reviews, and comments.
Track Issues: Manage tasks and bugs with GitHub’s issue-tracking system.
Use CI/CD: Automate testing and deployment of code with GitHub Actions.
What is Version Control?
Version control is a system that tracks changes to files over time, enabling multiple people to collaborate effectively. It allows users to roll back to previous versions and manage different versions of a project with ease. While it is commonly used for managing code, version control can also track changes in other file types, including documents and configuration files.
How many types of version controls do we have?
Types of Version Control Systems
Local Version Control Systems:
These store versions on a local computer.
An example is RCS (Revision Control System), which keeps track of changes in a single file, but this type doesn't work well for team collaboration.
Centralized Version Control Systems (CVCS):
In these systems, all file versions are stored on a single central server.
Users can check out files, make changes, and commit them back to the server. However, if the server goes down, team members can’t access or collaborate on the project.
Examples: CVS (Concurrent Versions System), SVN (Apache Subversion), Perforce.
Distributed Version Control Systems (DVCS):
In a DVCS, each user has a complete copy of the repository with all history and versions on their local machine.
This enables offline work, and users can commit changes locally before sharing them with others, making collaboration more flexible and resilient.
Examples: Git, Mercurial, Bazaar.
Why do we use distributed version control over centralized version control?
Distributed Version Control Systems (DVCS), like Git, are preferred over Centralized Version Control Systems (CVCS), such as SVN, for their flexibility and efficiency. Here are the main advantages of DVCS:
- Offline Work: Users have a complete copy of the repository, enabling them to commit changes and create branches without an internet connection.
Reduced Server Dependency: Each user’s local copy means that the system remains resilient, as the repository can be restored from any local copy if the central server fails.
Efficient Collaboration: DVCS allows for faster branching and merging, enabling developers to work independently and share updates when ready, reducing conflicts.
Better Performance: Local operations like commits and logs are significantly quicker since they don’t require server access.
Enhanced Security: Each repository copy acts as a backup, minimizing data loss risk, while allowing for controlled access to sensitive data.
Deep Dive in Git & GitHub for DevOps Engineers
Why Git is Important?
Git is important for modern software development because it enables efficient collaboration, project organization, and version management. Here’s why Git is essential:
Collaboration: Git allows multiple developers to work on the same project simultaneously without overwriting each other’s changes, thanks to features like branching and merging.
Version History: Every change is saved as a "commit," creating a timeline of all changes made to a project. This makes it easy to review history, revert to previous versions, or identify when and by whom changes were made.
Branching: Git’s branching feature allows developers to work on features or fixes in isolation, making it easier to experiment, develop, and test without affecting the main codebase. Branches can be merged back into the main project once tested.
Backup and Recovery: Because Git is distributed, every team member has a complete copy of the project, ensuring project redundancy. This makes it easier to recover if there’s a failure on a central server.
Widely Supported: Git is compatible with various tools and platforms (like GitHub, GitLab, and Bitbucket), and it's widely used in the software industry, making it a key skill for developers.
Difference Between the Main Branch and Master Branch
The terms "main" and "master" in Git refer to branch names in a repository, typically representing the primary branch where the latest stable version of the code is stored. However, there are subtle differences and reasons behind these two terms:
Historical Default:
Originally, "master" was the default name for the primary branch in Git.
Recently, many Git platforms (like GitHub, GitLab, etc.) have adopted "main" as the default branch name for new repositories, partly to promote inclusive terminology and move away from language with historical connotations.
Usage:
"Master" and "main" are functionally the same; they represent the main branch in the project that usually holds the latest, stable version of the code.
Teams can choose which branch name to use, or even rename "master" to "main" in existing projects if they prefer.
Compatibility:
- Newer repositories on platforms like GitHub default to "main" for consistency. However, both names are supported in Git, and you can configure either as the primary branch in your project.
Difference between Git and GitHub
Feature | Git | GitHub |
Purpose | A version control system to track code changes locally | A cloud-based platform for hosting Git repositories online |
Functionality | Manages versions, commits, and branches | Adds collaboration tools like pull requests, issue tracking, and code reviews |
Usage | Command-line tool installed locally on your computer | Web-based platform accessible from anywhere |
Scope | Distributed, standalone version control | Centralized hosting and collaboration service for Git repositories |
Connectivity | Works offline for commits and version control | Requires internet connection for accessing repositories |
User Interface | Command-line interface (CLI), some GUIs available | Web interface with user-friendly tools |
Ownership | Open-source software | Owned by Microsoft, offers both free and paid plans |
Create a new repository on GitHub
Sign in to GitHub:
- Go to GitHub.com and log in to your account.
Navigate to the Repositories Page:
Click on the "+" icon in the top right corner of the page.
Select "New repository" from the dropdown menu.
Fill Out Repository Details:
Repository Name: Enter a unique name for your repository.
Description (optional): Provide a short description of your project.
Public/Private: Choose whether you want the repository to be public (visible to everyone) or private (only you and selected collaborators can see it).
Initialize the Repository:
You can choose to initialize this repository with a README file. This is recommended as it provides a basic overview of your project.
Optionally, you can add a
.gitignor
e
file to specify which files or directories to ignore in the repository.You can also choose a license for your project from the available options.
Create the Repository:
- Click the "Create repository" button at the bottom of the page.
Clone the Repository (optional):
- After the repository is created, you’ll see options to clone it to your local machine. You can copy the URL and use Git commands to clone it, or you can use GitHub Desktop or another Git client.
Example Git Command to Clone
If you choose to clone the repository, use the following command in your terminal:
git clone <repository-url>
Replace <repository-url>
with the URL of your newly created repository.
What is the difference between local & remote repositories? How do you connect local to remote?
Difference Between Local and Remote Repositories
Feature | Local Repository | Remote Repository |
Definition | A repository stored on your local machine. | A repository hosted on a remote server, typically on a platform like GitHub, GitLab, or Bitbucket. |
Accessibility | Accessible only from the machine where it is stored. | Accessible from anywhere with internet access. |
Version Control | Maintains the entire history and versions locally. | Contains a centralized version of the repository for collaboration. |
Backup | It's not automatically backed up unless you manually copy it. | Usually backed up on the server, providing redundancy. |
Usage | Used for local development and testing. | Used for collaboration and sharing code with others. |
How to Connect a Local Repository to a Remote Repository
Create a Remote Repository:
- First, create a new repository on a platform like GitHub, GitLab, or Bitbucket, as described in the previous response.
Open Your Local Repository:
Open your terminal (or command prompt) and navigate to your local repository directory using the
cd
command:cd path/to/your/local/repository
Add Remote Repository:
Use the
git remote add
command to connect your local repository to the remote one. Replace<remote-name>
(commonlyorigin
) with the desired name for the remote, and<repository-url>
with the URL of your remote repository:git remote add <remote-name> <repository-url>
Example:
git remote add origin https://github.com/username/repository-name.git
Verify Remote Connection:
You can check if the remote has been added correctly by running:
git remote -v
Push Changes:
After making changes in your local repository, you can push them to the remote repository using:
git push <remote-name> <branch-name>
Example:
git push origin main
Subscribe to my newsletter
Read articles from Vanshika Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Vanshika Sharma
Vanshika Sharma
I am currently a B.Tech student pursuing Computer Science with a specialization in Data Science at I.T.S Engineering College. I am always excited to learn and explore new things to increase my knowledge. I have good knowledge of programming languages such as C, Python, Java, and web development.