Git Basics: Understanding Version Control and GitHub
- user
- May 24, 2026
- 0 comments
Git Basics: Understanding Version Control and GitHub
Introduction
As part of my DevOps learning journey, I have started learning Git and GitHub. Git is an essential tool for developers because it helps us track code changes, maintain different versions of our projects, and collaborate with other developers.
In this blog, I’ll cover the basic Git concepts and commands I have learned so far.
1. What is Git?
Git is a distributed version control system that tracks changes in files and source code.
It allows us to:
-
Track changes made to our code.
-
Maintain a history of changes.
-
Restore previous versions when required.
-
Work with branches to develop features independently.
-
Collaborate with other developers.
Git is installed on our local computer or server and manages a repository containing our project’s version history.
2. What is GitHub?
GitHub is a cloud-based platform that hosts Git repositories remotely.
We can push our local code to GitHub, pull changes from a remote repository, and collaborate with other developers.
The basic difference is:
-
Git: The version control software that tracks changes.
-
GitHub: A platform where we can host and collaborate on Git repositories.
3. Installing Git on a Linux Server
On Linux distributions that use the yum package manager, such as older versions of Amazon Linux and CentOS, we can install Git using:
sudo yum install -y git
For newer Linux distributions, the package manager may be different. For example, on Ubuntu, we can use:
sudo apt update
sudo apt install -y git
To verify the installation:
git --version
4. Initializing a Git Repository
First, navigate to your project directory:
cd my-project
Initialize Git using:
git init
This creates a .git directory that stores Git’s repository data and version history.
After initialization, Git can track changes in the project directory. However, files are not automatically committed just because we run git init.
5. Understanding the Git Workflow
Git has three important areas to understand:
-
Working directory: Where we create and modify our project files.
-
Staging area: Where we prepare changes that we want to include in the next commit.
-
Local repository: Where Git stores committed snapshots of our project.
The workflow looks like this:
Working Directory → Staging Area → Local Repository → Remote Repository (GitHub)
Step 1: Check the status
git status
This command shows which files are untracked, modified, or staged.
Step 2: Add files to the staging area
git add .
This stages new and modified files in the current directory and its subdirectories, subject to Git’s ignore rules.
Step 3: Commit the changes
git commit -m "first commit"
This creates a commit containing the staged changes in the local repository.
A commit acts as a recorded checkpoint in the project’s history.
6. Connecting the Local Repository to GitHub
First, create a repository on GitHub. For this example, I’ll use my practice repository:
https://github.com/rahulshirode/git-test
Connect the local repository to GitHub using:
git remote add origin https://github.com/rahulshirode/git-test.git
Here:
-
git remote addadds a remote repository. -
originis the conventional name for the remote. -
The URL identifies the GitHub repository.
To verify the remote:
git remote -v
7. Pushing Code to GitHub
After committing the changes, push the local branch to GitHub.
For example, if your branch is named main:
git branch -M main
git push -u origin main
The -u option sets the upstream relationship, making subsequent pushes from that branch easier.
8. GitHub Authentication
When using HTTPS, GitHub no longer accepts your regular account password for Git operations.
Depending on your authentication setup, you can use a Personal Access Token (PAT) instead of a password, or use a credential manager or SSH authentication.
Important: Never share your access token or store it directly in your source code. Treat it like a password.
Conclusion
These are the basic Git commands I have learned as I continue my DevOps learning journey.
Understanding Git’s working directory, staging area, local repository, and remote repository has helped me understand how code changes are tracked and how projects are managed using version control.
I’ll continue exploring Git commands, branching, merging, conflict resolution, and collaboration through hands-on practice.