Getting Started with Git and GitHub: A Beginner’s Guide to Version Control


Overview
Exploring Git: A Fundamental Tool in DevOps
In this lab session, we will dive into one of the most essential tools in the DevOps ecosystem — Git. Whether you're a developer, tester, or operations engineer, understanding Git is crucial for efficient collaboration and version control.
We'll walk you through:
What Git is
Why it is widely used in modern software development
Git Stages
Key Git commands that help manage your codebase effectively
Git Hub
By the end of this lab, you'll gain hands-on experience with Git and understand how it fits into the broader DevOps workflow.
What is Git?
Git is a Version Control System (VCS), also known as Source Code Management (SCM). It is widely used to manage and track changes in source code throughout the software development lifecycle. Git plays a crucial role in ensuring code stability, enabling teamwork, and supporting agile development practices. Git is platform independent also it is free and open-source.
Why Git?
With Git, you can:
Keep a history of every change made to your code
Collaborate with other developers without overwriting each other’s work
Easily switch between different versions or branches of a project
Revert to previous versions if something goes wrong.
Git makes it easy to create isolated branches for new features, bug fixes, or experiments—then merge them into the main codebase when they’re ready.
Git Stages
Git uses a three-stage architecture to manage your code changes effectively. Understanding these stages helps you take full control over what gets committed and when.
The 3 Stages of Git
Working Directory
Stating Area
Repository
Working Directory
This is your local project folder where you add, edit, or delete files. At this stage, Git is aware of the files, but it doesn’t track any changes until you explicitly tell it to. Modified or newly created files remain untracked until they are added to the next stage.
Stating Area
This stage is like a rough draft or a preparation zone.
When you run git add
, you move changes from the working directory to the staging area. Here, you can review and group changes you want to include in your next commit—giving you fine-grained control over what gets saved.
Repository
The repository is like your project’s folder.
When you commit staged changes (git commit
), they’re stored in the local repository along with a snapshot of the project at that point in time. Git also keeps a full history of these commits, enabling you to track and revert changes when needed.
Git Commands
Git offers a wide range of commands to help you manage your source code efficiently. Here are some of the most frequently used commands that you'll encounter in your daily workflow:
To install git in your server
yum install git -y
where
yum: yellow dog updated modifier, package manager in linux
-y: installing git without permission
To commit changes
git commit -m"<<message related to commit>>" <filename>
Eg: git commit -m"changes made to file sample" sample
To show commits
git log
To check status of files
git status
To change configurations like name, email
git config user.name"<name>"
git config user.email"<email>"
To get history of commits
git reflog
To get latest 2 commits
git log -n 2
To get commit ID+ message
git log --oneline
To hide the files
git ignore
To get the deleted commit back
git cherry-pick <commit-ID>
To work on different versions at same time, all the changes that we make will be in a “master” branch
git branch <branch-name>
To merge the files into master branch from another branch
git merge <branch-name>
To create and go to the branch at the same time
git checkout -b <branch-name>
To delete specific latest commit
git revert <commit-ID>
Sometimes after committing changes, you might realize there's a mistake in your code. Instead of making a new commit just to fix the previous one, Git allows you to delete or amend the latest commit before pushing it. We will have two types in this case
Only deleting the commit and deleting the commit along with data.
To delete commit
git reset -- soft HEAD~1
where 1: latest commit
To delete commit and data
git reset -- hard HEAD~1
where 1: latest commit
To add another commit to the previous commit
git commit --amend --no-edit
When we wanted to switch branch while working on the other branch, in order to avoid losing data in the current branch we “Stash” the changes, so that the we will not loose the change.
git stash apply
GITHUB
GitHub is a cloud-based platform used to store, manage, and share code. It builds on top of Git, allowing developers to collaborate on projects from anywhere in the world.
With GitHub, you can:
Host repositories publicly or privately
Track changes and contributions using Git
Collaborate through pull requests, code reviews, and issues
Automate workflows with GitHub Actions
Showcase your work and contribute to open-source projects
GitHub has become the central hub for developers, teams, and open-source communities to build, maintain, and scale software together.
Understanding GitHub with a Real-World Example
When Developer 1 wants to share their code on GitHub, they must first push the code using the git push
command. But before that:
- They need to connect their local Git repository to the remote GitHub repository using:
git remote add origin <repository-URL>
Once connected, they can push the code (typically a specific branch) to GitHub:
git push -u origin <branch-name>
Note: It’s not just the code being pushed, but the branch containing the changes.
If Developer 2 is accessing the project for the first time, they won’t have any of the previous code. So, they need to clone the repository:
git clone <repository-URL>
This command downloads the entire codebase—including all previous commits and branches—onto their local machine.
After making changes, Developer 2 stages and commits the updates locally and the code will be available for rest of the team.
Since Developer 1 already has the project locally, they don’t need to clone again. Instead, they simply pull the latest changes made by Developer 2:
git pull origin <branch-name>
This command fetches the updates from GitHub and merges them into Developer 1's local branch.
This simple flow demonstrates the power of GitHub in enabling seamless code sharing and collaboration between developers, no matter where they are.
The common rule that is used in git/github- PULL BEFORE A PUSH
Conclusion
Git and GitHub aren’t just tools—they’re essential parts of how modern development teams collaborate and build high-quality software. From tracking changes to managing code versions and enabling teamwork across time zones, they bring structure and reliability to the development process.
By understanding the basics—from staging files to pushing code and collaborating through pull requests—you’re already on your way to becoming a more efficient and confident developer.
The more you use Git and GitHub, the more natural it becomes—so don’t just read about it, start experimenting and building!
References and Acknowledgments
This blog has been created by gathering insights from multiple sources to ensure accuracy and clarity. The following platforms were used for research and refinement:
My personal learning course on devOps
ChatGPT – for refining language, improving structure, and enhancing overall readability
Subscribe to my newsletter
Read articles from pragna sree directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

pragna sree
pragna sree
Hello Everyone! I am Pragna, currently working as technical support engineer for a MNC. I recently developed interest in devOps and started learning it from scratch.