CoDeKu DevOps Academy Blog - DevOps & Cloud Blogging Platform

Mastering Git: A Beginner Friendly Guide to Version Control

In the world of software development, making changes is inevitable — and sometimes, messy. That’s where Git comes in.
In this beginner-friendly guide, I’ll walk you through Git, the most popular version control system used by developers around the world. Whether you’re a student, freelancer, or team collaborator, mastering Git will help you manage your projects efficiently and confidently.
Introduction to Git
Git is a distributed version control system that facilitates productive collaboration amongst developers by tracking file changes over time. It is essential for software development and the most popular version control system in the world.
Features of Git
● Distributed system: Every developer has a full copy of the project history.
● Tracking changes: You can see what was changed, when, and by whom.
● Branching and merging: You can create separate branches to work on new features or bug fixes, then merge them back into the main code.
● Collaboration: It enables teams to collaborate efficiently through platforms like GitHub or GitLab.
What is GitHub? Are Git and GitHub the same or different?
GitHub is an online platform that hosts Git repositories. It allows developers to store, manage, and collaborate on code repositories in the cloud.
Git is not the same as GitHub.
Configure Git for the First Time
Before making your first commit, it’s important to configure Git with your personal information. This step ensures that your name and email are correctly associated with your commits.
Screenshot 1
Screenshot 2
General Git Features
To start tracking a project with Git, you first need to initialize a Git repository using the command.

Screenshot 1
This tells Git to begin monitoring the current folder. Once executed, Git creates a hidden .git directory inside the folder. This directory contains all the necessary files Git needs to track versions, manage branches, and store history.
Staging Files / Adding Files to Git Repository
Staged files are files that are ready to be committed to the repository you are working on.
When you first add files to an empty repository, they are all untracked. To get Git to track them, you need to stage them, or add them to the staging environment.

Screenshot 1

We can add all the staging files into the repository as,

Screenshot 1
Making a Commit of Repository
In Git, a commit is a snapshot of your project’s files at a particular point in time, effectively creating a version of your project. It’s like a save point, recording the changes made since the last commit along with a descriptive message explaining the modifications.
When we commit, we should always include a message.

Screenshot 1
Git Commit without Stage
Sometimes, when you make small changes, using the staging environment seems like a waste of time. It is possible to commit changes directly, skipping the staging environment.

Screenshot 2
Status of Files and Log
The git status command displays the state of the working directory and the staging area.
Git Status Command Output
Files status in a more comprehensive way: git status --short to show a concise summary of the current status of your working directory and staging area.
Git Status Short Command Output
Git Clone from GitHub
We can clone a forked repo from GitHub to our local machine. A clone is a full copy of a repository, including all logs and versions of files. Move back to the original repository, and click the green “Code” button to get the URL to clone. Copy the URL.

Now in Git Bash, enter the following command to clone the copied repository onto your local machine:
git clone <Copied repository URL>
Git clone command example
To specify a specific folder to clone that repository into, add the folder name after the repository URL like this:
git clone <Copied repository URL> <folder name>
Git Branching
In Git, a branch is a pointer to a specific commit, essentially a snapshot of your code at a certain point in time. It allows you to work on new features, bug fixes, or experiments without directly modifying the main codebase.
Why do we use Git branches?
For teamwork and to try new things or fix bugs in our projects without affecting the main codebase.
Let’s practice how Git branching works:

⦿ First, select any repository on your GitHub to clone into your local folder. Use the git clone command:

Git clone
⦿ Then open it in VS code and Create a new branch on existing branch,
Create new branch
⦿ Use git branch to list all branches that have git repository and now it has 2 branches like test1 and master.(e.g., test1 and master):
Git branch list
⦿ Switch to test1 branch and make changes. These changes won’t affect the master branch:
Working on test1 branch
⦿ Finally, switch back to the master branch. The changes from test1 are not visible. To combine them, use the git merge command:
Merging branches
The git merge command is used to merge changes from one branch into another usually from a feature branch into the main (or master) branch.
How to Delete a Git Branch in a Particular Repository?
Sometimes, you may want to clean up old or unnecessary branches in your repository. Whether it’s a local or remote branch, Git provides simple commands to delete them.
● Deleting a Local Branch:
You can delete a local branch with the following command:
git branch -d <branch_name>
Use -d to force delete if the branch has unmerged changes.
Deleting Local Branch
● Deleting a Remote Branch:
To delete a branch on the remote repository (e.g., GitHub), use the command below:
git push origin --delete <branch_name>
Deleting Remote Branch
Git Pull Command
The purpose of the git pull command is to update your local repository with changes from the remote repository. It essentially combines two operations:
  • git fetch – Downloads the changes from the remote repository.
  • git merge – Integrates those fetched changes into your current local branch.
This ensures your working directory stays up-to-date with the latest changes from your teammates or the main project.

Git Pull Command Example
The git pull command downloads content from the required remote repository and merges it into your current branch. It effectively combines fetching and merging into one step.

In contrast, git fetch downloads commits but does not merge — it allows you to review changes before merging.

Syntax of the git pull command:
git pull <remote> <branch>
  • remote – Usually origin, the default name for your remote repository.
  • branch – The branch you want to pull updates from.
Git Pull Command Screenshot When you run the git pull command:
  • It fetches the latest commits from the specified branch of the remote repository.
  • Merges those changes into your current local branch.
  • If conflicts arise, you’ll need to resolve them manually before the merge is completed.
Pull local repository into GitHub :
Git pull is used to pull all changes from a remote repository into the branch we are working on. It is a combination of fetch and merge. Use it to update your local Git.
Pull branch from GitHub :
First, check which branches we have and where we are working at the moment by ‘git branch’ command. Since we do not have the new branch on our local Git which is to be pulled from the GitHub, we use this to see all local and remote branches:
git branch -a
For viewing only remote branches:
git branch -r

Now, the new branch is seen in the console but it is not available on our local repo. So, let’s check it out using:
git checkout <branch name>
Now run ‘git pull’ to pull that branch on our local repo. We can now check the available branches using ‘git branch’.
Push Branch to GitHub
First, let’s create a new local branch which we will be pushing to GitHub. Enter the command as git checkout -b <branch name> . You can check the status of the files in this current branch using git status .
Commit all the uncommitted changes for all the files in this branch using git commit -a -m “Message” . Now push this branch from our local repo to GitHub using git push origin <branch name> .
🔚 Conclusion: Your Git Journey Starts Here
Congratulations! You’ve just taken your first solid steps into the world of Git and version control. From understanding what Git is, to configuring your setup, making commits, branching, and syncing with GitHub — you now have the essential knowledge to manage your projects confidently and collaborate with others effectively.
Mastering Git might take time and practice, but the foundation you’ve built here will empower you to work smarter and keep your codebase organized. Keep exploring, keep experimenting, and soon you’ll be navigating Git like a pro. Happy coding! 🚀

Share This Article

Sasanka Ranawaka
Sasanka Ranawaka

I'm an undergraduate at the University of Sri Jayewardenepura, passionate about technology, coding, and cybersecurity. I enjoy working on software projects, networking setups, and machine learning models. With experience in languages like Java, Python, C#, and full-stack development (MERN), I’m always exploring new ways to solve problems and grow in the tech field.

Articles: 3

6 Comments

Comments are closed.