Version Control and Git Basics


What you’ll learn
Introduction to Version Control and Git Basics.
Branching and Merging.
Advanced Git and GitHub.
Tools and Requirements
Software: Installation of Git.
Accounts: Creation of a GitHub account.
Mindset: Collaboration and ready to learn.
Version Control
Version Control can be defined as a system that records changes made to a file or set of files over time so that one can recall specific versions later.
For instance, imagine working on a big school assignment in a notebook. Every time you make changes, you write the date on the page and keep older drafts at the back of the notebook instead of erasing them. This way, if your current version gets messy, you can flip back and look at what you had before. This is what we call Version Control.
Version Control also allows multiple people work on the same project without overwriting each other’s work.
Essentially, version control is like a time machine for your code. It solves problems such as:
Collaboration with others by enabling Developers collaborate with each other without creating mess (e.g., emailing files back and forth).
Keep track of changes by tracking of what changes were made, when and by whom.
Accidental deletion or breaking code: It makes it easy for Developers to recover files/work they accidentally deleted or broke within a repository(folder).
Importance of Version Control
Collaboration: Version Control allow teams work concurrently on the same project reducing the risk of overwriting or losing work.
Backup and restore: Version Control ensure changes are tracked and can be reverted, offering robust backup system.
Branching and merging: Teams can work in parallel or different features or fixes and combine them seamlessly.
Tracking and accountability: Every change is attributed to a user, providing a clear history of project evolution and accountability.
Introduction to Git
Git is a tool running on your computer, tracking changes to your code files.
Git is like your smart notebook assistant helping you track every single change you make, what you changed, when you changed it, and why, even letting you jump back to any previous version of your work/assignment.
Here is how Git works:
Snapshot of your project: Git takes snapshots (called commits) of your code at specific points in time. Each commit is like a checkpoint that saves the state of your project.
Local operation: Git works on your local computer without needing an internet connection.
Branching: Git lets you create branches which are like separate copies of your project. You can experiment on a branch without affecting the main code, and later merge your changes back.
Collaboration: Git allow multiple developers work on the same project by tracking everyone’s changes and merging them together.
Key features of Git
Speed and Efficiency: Git is designed for performance. Operations like commit, merge and branching are fast and efficient.
Distributed nature: Every user has a copy of the repository, including it’s history, ensuring data integrity and redundancy.
Branching model: Git’s branching system is lightweight making branching and merging operations fast, encouraging workflow that leverages branching and merging without causing overheads.
GitHub
GitHub however, is a web-based platform that hosts Git repositories (folders for your project that Git tracks). It’s basically a cloud storage for your code, but with extra features to make collaboration and version control easier.
Setting up and configuring Git
Git is compatible with Windows, macOS, and Linux systems, with installation process varying depending on the operating system.
Windows
For installation on Windows machine, follow these steps:
Download git installer from the official git website here: git official website
Run the installer and follow the instructions thereafter.
After the installation is complete, open the command prompt and type the command:
git —version
It will output the version of git installed.
macOS
For installation on macOS machine, follow these steps:
Open the terminal and type the command here:
brew install git
to install using homebrew.Or you can install git without using homebrew from the official git website: git official website
verify the installation by typing the command:
git —version
on the terminal.
Linux
For installation on Linux machine, follow these steps:
Open the terminal
Install git using distributed package manager.
Ubuntu/Debian:
sudo apt-get update sudo apt-get install git
Fedora:
sudo dnf install git
Verify installation by running the command:
git —version
on the terminal.
Configuring Git
It is always important to configure the user information used to commit changes to git. This is essential for collaboration and maintaining a clear history of changes.
Setting username and email
After the installation of git and creation of a GitHub account, it’s essential to configure your username and email through the following steps:
Open the terminal.
Set your username with the command
git config --global user.name <your name>
. “Your name“ in this case should the Github name, e.g., mine isLord_Abiolla
Then set your email address using the command
git config --global user.email <your email address>
“Your email address“ should be the email you used to create your github account.To check configurations, use the command
git config —list
Basic Git commands
These are commands that are essential for tracking changes in your projects and collaborating with others.
Git repository can be obtained in one or two ways:
You can take a local directory that’s currently not under version control, and turn it into a Git repository, or
You can clone an existing Git repository from elsewhere.
a). Creating new repository
- Initializing a Repository in an existing directory
If you have a project directory that is currently not under version control and you want to start controlling it with Git, you first go to that project’s repository as shown below;
On the terminal type cd my_project
Once you’re in the project’s repository, type git init
. This creates a new sub-directory named .git
that contains all of your necessary repository files - a Git repository skeleton. At this point, nothing in your project is tracked yet.
- Cloning an existing repository
Cloning means getting a copy of an existing Git repository. For example, a project you’d like to contribute to - the command you need it git clone <url>
.
For example, if you want to clone the Git linkable library called libgit2
, you can do so like this:
$ git clone https://github.com/libgit2/libgit2
This command creates a directory named libgit2
, initializes a .git
directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go inside the new libgit2
directory that was just cloned, you’ll see the project files in there, ready to be worked on or used.
b). Adding and committing changes
The git workflow can be categorized into three sections as shown below;
Working directory - This is where you make your changes by editing files.
Staging area - This is the place to prepare your changes before committing them.
Repository - This is where the committed changes are saved with a message.
Within your working directory, before adding and committing, use the git status
command to see what has changed in your project. You may see;
Untracked files which are basically new files.
Modified files which are existing files that have been edited.
Staged files are files ready to be committed.
Adding changes to the staging area, use the command git add <filename>
.
For example:
git add index.html
, add index.html file to the staging area.
git add .
, will add all changed and new files in the current directory to the staging area.
git add index.html styles.css
, will add both index.html and styles.css files to the staging area.
Committing the changes: A commit is like taking a picture of your current work with a message describing it as shown here; git commit -m "Your message here"
.
The commit message should always be short, clear and descriptive enough. for example;
git commit -m "Add navigation bar to homepage"
Example workflow summary
# Check what’s changed
git status
# Add changes to staging
git add .
# Save the changes in a commit
git commit -m "Add footer section to website"
NOTE: You must always add files before committing them, a commit message should explain what and why, not how, and finally you can commit multiple times before pushing to GitHub.
Branching and Merging
Branching and merging are features of Git that allows you work on different tasks independently and combine them safely later on.
A branch in git is like a separate line of development in your project. It is a copy of your original code, but on a different branch where you can make changes without affecting the main code(usually the main
branch).
Branching allows multiple people work in parallel without interfering with each other.
A real world analogy:
Imagine you are writing a book with a friend:
The
main
branch is the published book.You want to add a new chapter, but you’re not sure if it will make the cut.
So you create a new branch to write your chapter.
Once it is ready, you merge it into the main book.
How to work with Branches
git branch
: A command used to view all branches.git branch feature-xyz
: A command used to create a new branch. This will create the new branch but does not switch to it yet.git checkout feature-xyz
: This command switches you from the current branch to the new branch which in this case isfeature-xyz
. Sometimes you can use the commandgit switch feature-xyz
To combine both the commands, i.e., create a branch and switch to it immediately, use the command
git checkout -b feature-xyz
orgit switch -c feature-xyz
.
Example use case
You have a live website project and you are on the main branch. You want to add a contact form without messing up the live site.
# Create and switch to a new branch
git checkout -b add-contact-form
# Add files or edit code
git add contact.html
git commit -m "Add contact form page"
# Work continues here...
Merging branches
Once a feature on a branch is tested and ready, you can merge it back into the main branch. Let’s have a practical example;
Switch to a branch you want to merge into (e.g., main):
git checkout main
Merge the feature branch into main.
git merge add-contact-form
What if there are conflicts?
Sometimes, Git cannot automatically merge because the same part of a files was changed in both branches. This is called a merge conflict.
To resolve the conflict;
Git will mark the file and show where the conflict is.
Open the file and manually edit the conflicting lines.
After resolving, run:
git add conflicted-file
git commit
Branching and merge cheat sheet
Command | Action |
git branch | List branches. |
git branch new-branch | Create new branch. |
git checkout branch-name | Switch to a branch. |
git checkout -b new-branch | Create and switch to a branch. |
git merge other-branch | Merge into current branch. |
git branch -d branch-name | Delete a branch. |
GitHub
GitHub is a web based platform that helps you store, manage, and collaborate on Git repositories online. It is basically a cloud backup for your Git projects that allows you to:
Share code with others.
Collaborate on software projects.
Track changes and issues.
Showcase your work.
NOTE: Git is a version control system, and GitHub is a cloud service for Git repositories.
Features of GitHub
Remote storage: GitHub stores our Git repositories online so thy are backed up and accessible from anywhere.
Collaboration tools: Through GitHub, developers can share code, review changes, and discuss improvements.
Social features: GitHub acts as a social network for developers. You can follow other people’s projects, contribute to open source software or showcase your work.
Extras: GitHub offers tools like issue tracking(for reporting bugs), pull requests(for proposing or reviewing changes), and GitHub actions(for automating tasks).
Why use GitHub?
Collaboration made easier: GitHub simplifies the process of working with others on projects and makes it easy to collaborate on code.
Open source and private projects: GitHub enables the creation of Open source or private repositories for proprietary work.
Integrated project management tools: With issue tools, pull requests and project boards, GitHub provides suite of tools for project management alongside version control.
Key GitHub Concepts
Concept | Description |
Repository | This is a project or folder that Git tracks. On GitHub, its is like your project’s home. |
Remote | This is a version of your project that is hosted elsewhere (like GitHub). |
Clone | This means to copy a GitHub repository to your local computer. |
Push | This is the act of sending your local commits (commits made on the local computer) to GitHub. |
Pull | This means to get the latest commits from GitHub to your local computer. |
Fork | This is to make your own copy of someone else’s repository. |
Pull request (PR) | This is to ask to merge changes into someone else’s branch. It’s mostly used in collaboration. |
Creating a GitHub account: Go to https://github.com, and sign up for free.
Create a new repository
Click the + icon the go to
New Repository
Fill in the:
Repository name: e.g.,
my-first-repo
Description (optional)
Choose
public
orprivate
Check “Initialize with a README“ (optional)
Click Create repository
Clone a repository to your computer
git clone https://github.com/your-username/my-first-repo.git
This creates a local copy of the repository on your local computer.
Make changes Locally
cd my-first-repo echo "Hello GitHub!" > hello.txt git add hello.txt git commit -m "Add hello.txt with greeting"
Push changes to GitHub
git push origin main
origin
= The remote GitHub repositorymain
= The branch name.
Opening a Pull Request (PR)
Once a branch is pushed to GitHub, you can:
Go to your repository on GitHub.
You’ll see a message like:
"Compare & pull request"
Click it, write a brief summary, and click Create pull request.
Pull requests allow collaborators to review your code before merging into the main project.
Forking a Repository
Let’s say you want to contribute to someone else’s repository.
Go to their GitHub repository page.
Click Fork (top right).
This creates your own copy under your account.
Clone it, make changes, push, and open a pull request back to the original repo.
GitHub workflow for your own project
# 1. Clone the repo (first time only)
git clone https://github.com/your-username/project.git
# 2. Navigate into it
cd project
# 3. Make changes, then:
git add .
git commit -m "Describe your changes"
git push
GitHub workflow when collaborating
# Make sure you're up to date
git pull origin main
# Create a new branch
git checkout -b feature/your-feature
# Work, then stage and commit
git add .
git commit -m "Add feature"
# Push your branch
git push -u origin feature/your-feature
# Open a pull request on GitHub
Use case summary when creating a portfolio site and tracking it on GitHub
# Create project folder
mkdir portfolio
# cd into the directory
cd portfolio
# Initialize Git
git init
# Add your files (index.html, styles.css, etc.)
git add .
git commit -m "Initial commit"
# Connect to GitHub remote
git remote add origin https://github.com/your-username/portfolio.git
# Push to GitHub
git push -u origin main
Conclusion
Git is a version control system that helps you track changes in your project files and collaborate with others efficiently. It works locally on your computer, allowing you to create repositories, make commits (snapshots of your work), create branches for separate features or fixes, and merge changes safely.
GitHub, on the other hand, is a cloud-based platform that hosts your Git repositories online, making it easy to back up your work, collaborate with teammates, and contribute to open-source projects. You can clone repositories from GitHub, push your local commits to the cloud, pull updates from others, and open pull requests to propose changes.
Git uses commands like git init
, git add
, git commit
, git branch
, git checkout
, git merge
, git push
, and git pull
to manage workflow, while GitHub provides an interface for hosting, reviewing, and sharing code. Therefore, Git and GitHub form a powerful toolkit for version control and collaborative development.
Subscribe to my newsletter
Read articles from Lord Abiolla directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Lord Abiolla
Lord Abiolla
Passionate Software Developer with a strong enthusiasm for data, technology, and entrepreneurship to solve real-world problems. I enjoy building innovative digital solutions and currently exploring new advancements in data, and leveraging my skills to create impactful software solutions. Beyond coding, I have a keen interest in strategic thinking in business and meeting new people to exchange ideas and collaborate on exciting projects.