Introduction
Modern software development involves constant changes to code. Developers add features, fix bugs, and collaborate with others. Without a system to manage these changes, projects can quickly become disorganized.
This is where version control becomes essential.
Git is a distributed version control system that tracks changes in code, allowing developers to manage project history efficiently. GitHub is a cloud-based platform that hosts Git repositories and enables collaboration among developers.
Together, Git and GitHub help developers:
- Track changes in their code
- Work safely without losing previous versions
- Collaborate with other developers
- Manage and review code contributions
In this guide, you will learn how to install Git, create repositories, track changes, and collaborate using GitHub.
Overview of Version Control
Version control systems allow developers to:
- Track changes in files over time
- Revert to previous versions when needed
- Collaborate without overwriting each other's work
- Maintain a clear history of project changes
Why Git?
Git is one of the most widely used version control systems because it is:
- Fast
- Distributed
- Reliable
- Widely supported
Git vs GitHub
Tool Description
Git A version control system installed on your computer
GitHub A cloud platform used to host and share Git repositories
In simple terms:
- Git manages your code history
- GitHub stores and shares your repositories online
Installing and Setting Up Git
Before using Git, you need to install it on your computer.
Installing Git
Windows
- Visit the Git website: https://git-scm.com
- Download the Windows installer.
- Click to Download.
- Run the installer and follow the default setup options.
Verifying Installation
After installation, open your terminal or command prompt and run:
git --version
Example output:
git version 2.52.0.windows.1
This confirms Git is successfully installed
Configuring Git
Git uses your name and email to label commits.
Set your username:
git config --global user.name "Your Name"
Set your email:
git config --global user.email "your@email.com"
Check your configuration:
git config --list
This displays the settings currently configured for Git.
Creating a Git Repository
A repository (repo) is a project folder that Git tracks
Initialising a Local Repository
Navigate to your project folder:
cd my-project
Initialize Git:
git init
This command creates a hidden .git directory that stores repository history.
Creating a Repository on GitHub
- Log in to GitHub.
- Click New Repository.
- Enter a repository name.
- Choose Public or Private.
- Click Create Repository.
GitHub will generate a remote repository where your code will be stored online.
You can add Description if you wish, then Click on Create Repository

Connecting Local Repository to GitHub
Add the remote repository:
git remote add origin https://github.com/username/repository-name.git
Check the remote connection:
git remote -v
This shows the remote repository URLs linked to your project.
Working with Files in Git
Git tracks file changes through a process involving staging and committing.
Checking Repository Status
Use:
git status
This command shows:
- Modified files
- Untracked files
- Files staged for commit
Staging Files
To stage a specific file:
git add filename.txt
To stage all changes:
git add .
Understanding the Staging Area
The staging area acts like a preparation space where you select which changes should be included in the next commit.
Workflow example:
Working Directory → Staging Area → Git Repository
Making Commits
A commit saves a snapshot of your project at a specific point in time.
Creating a Commit
git commit -m "Add homepage layout"
The -m flag allows you to include a commit message describing the change
Writing Good Commit Messages
Good commit messages should:
- Be clear
- Be concise
- Describe what changed
Example:
Fix login authentication bug
Add README documentation
Update navigation menu styling
Viewing Commit History
To see previous commits:
git log
This displays:
- Commit ID
- Author
- Date
- Commit message
Pushing Changes to GitHub
Once commits are made locally, they can be uploaded to GitHub.
Setting the Main Branch
Many repositories use main as the default branch.
Rename your branch if needed:
git branch -M main
Pushing to GitHub
Upload commits:
git push -u origin main
Explanation:
- origin → remote repository
- main → branch name
- -u → sets upstream tracking After this, future pushes can be done with: git push
Pulling and Updating Code
When working with remote repositories, you may need to update your local copy.
Fetch and Merge Updates
git pull
This command:
- Downloads changes from GitHub
- Merges them into your local repository This keeps your project synchronized with the remote repository.
Basic Collaboration Workflow
GitHub enables multiple developers to work on the same project.
Cloning a Repository
To download a project:
git clone https://github.com/username/repository.git
This creates a local copy of the repository.
Making Changes
Typical workflow:
- Clone repository
- Make code changes
- Stage files git add .
- Commit changes
git commit -m "Improve API validation" - Push updates
git push
Pull Requests (Overview)
A Pull Request (PR) is a feature on GitHub that allows developers to:
- Propose code changes
- Request reviews
- Merge contributions into the main project Typical process:
- Push changes to a branch
- Open a Pull Request on GitHub
- Team members review the code
- Changes are merged into the main branch
Common Git Commands Summary
Command Purpose
git init: Initialize a new repository
git status: Check repository state
git add: Stage files for commit
git commit: Save changes to repository
git log: View commit history
git remote add origin: Connect local repo to GitHub
git push: Upload commits to GitHub
git pull: Download and merge updates
git clone: Copy a repository from GitHub
Best Practices for Using Git
Write Clear Commit Messages
Explain what the change does and why it was made.
Commit Frequently
Small commits make debugging and tracking changes easier.
Keep Repositories Organized
Use meaningful file names and folder structures.
Pull Before You Push
Always update your local repository before pushing changes to avoid conflicts.
Conclusion
Git and GitHub are essential tools for modern software development. They allow developers to track changes, collaborate efficiently, and maintain reliable project history.
In this guide, you learned how to:
- Install and configure Git
- Create repositories
- Stage and commit files
- Push code to GitHub
- Pull updates and collaborate with others
Mastering this basic workflow will help you manage projects more effectively and collaborate confidently with other developers.
As your experience grows, you can explore advanced Git features such as branching strategies, merge conflict resolution, and automated workflows.
For now, the best way to learn Git is simple: use it regularly in your projects.








Top comments (0)