Introduction
Data science projects are usually a collaboration of different intertwined parts that are joined together to give a complete project and not just written code, it includes a dataset, python scripts, Sql queries, visualizations and documentation. As changes are done on these files tracking the different modifications becomes important. This is where Git becomes one of the most valuable tools for a data scientist.
What is Git, Git Bash and GitHub?
Git is a software developed to help the user to keep track of changes to their code files while git bash is the command-line window akin to the windows terminal command prompt that is used by users to type out their commands. While, GitHub is an online (cloud-based) platform that creates an environment for users to work together on projects and it also used to host computer code.
Rather than Git being understood as simply a way to pass code from user to GitHub, it is better thought of as a library that keeps records of the history of your project from start to finish. Git is used to manage the project locally on the computer while GitHub stores it online. It is also understood or can also be called a version control system that allows the user to:
- Experiment freely
- Return to previous versions
- Collaborate with others
- Maintain an organized workflow
The image is an example of a Git Bash terminal:
The image below is an example of a GitHub platform:
Uses of Git, Git Bash and GitHub.
Git being a version control system is used for various reasons. some of it uses are as listed below:
Tracking file history - Using commits(screenshots) it allows the user to return to previous versions in case something happens, tracks bugs an changes over time.
Team collaboration - It merges work done by different people and keep track of which changes were done by which user.
Offline local work - Because Git is well distributed, every user has a copy of the the project being worked on their personal computer.
Parallel Development - It works on different things at the same time without interfering with the main codebase.
Uses of Git Bash are as follows:
Running Git commands - Serves as a terminal that is used to execute commands like
git init,git commit,git push,git pullEnabling Unix/Linux commands on windows - Windows having its own inbuilt terminal (Power Shell and Command Prompt) it uses different syntaxes hence Git Bash brings standard Unix utilities like
cd,ls,mkdir,pwdjust to name a few directly to windows.Running shell scripts - It enables users to write and run automated automation tasks using standard Bash script files(
.sh) on a windows machine.Universal tutorial compatibility - It allows Windows users to follow along with Linux on macOs terminal instructions exactly.
Uses of GitHub?
It being a cloud based platform and it having many features it is used for the following :
Repositories - Also known as Repo(s), It is a storage folder where project code and history are found.
Version Control - A system that saves snapshots of code so you undo mistakes or compare old versions.
Branching & Merging - Creating a separate copy of code to test a new idea and then recombining it with the main project if it works.
Pull Requests - A request to review and merge code changes into a shared project.
Basic/Most Used Bash Commands
ls - Used to list files and folders
cd - Change directory
pwd Find the path of the current directory
mkdir - Make a directory
mv - Move files and folders
rm - remove files and folders
The Git Workflow
The Git workflow is a recipe or recommendation on how to use Git to manage code changes in a consistent, collaborative way.
It has four main stages, namely:
Working Directory
It is where the user actively works on their project. It is the computer local space where you create, edit and delete files. Changes made here aren't yet tracked by Git.Staging Area(Index)
Think of this as a preparation space. When the user has made changes they'd like to include in their next commit, they "stage" those changes, adding them to the staging area. Only staged chances make it to the next commit.Creating a Commit
A commit is a like a checkpoint in the user's project's history. Every commit usually describes a noteworthy change.
Create a commit:
git commit -m "Add patient age"
Commit as a checkpoint makes it easier to return to an earlier version if the new test fails or performs worse.
To view previous commits use:
git log --oneline.
- GitHub: The Remote Repository A commit saves history locally but GitHub stores a copy online so it can be backed up and shared.
After creating commits:
git push origin main
Uploads your project to GitHub.
If another team member adds new work, download it using:
git pull origin main
A common workflow is:
git pull origin main
git add .
git commit -m "Add patient age"
git push origin main
Essential Git Commands and Their Use Cases
git add
It stages changes, preparing them for the next commit.
Usage:
git add <file>stages a specific file;git add .stages all changes in the current directory.Example: After editing
index.html, rungit add index.htmlto stage the changes.
git status
It displays the state of your working directory and staging area, helping track which changes are staged, unstaged, or untracked.
Usage: Simply run
git statusExample: After modifying
index.html,git statuswill show that the file has been modified and is ready to be staged.
git commit
It records your your staged changes into the local repository, creatin a snapshot of your project at that point in time.
Usage:
git commit -m "Your commit messageExample: After staging your changes, run
git commit -m "Fix header alignment"to commit them with a descriptive message.
git reset
It undoes changes by moving the HEAD pointer and, optionally, modifying the index and working directory.
Usage:
git reset HEAD <file>unstages a specific file;git reset --hard HEAD~1resets the repository to the previous commit, discarding changes.Example: If you accidentally staged
style.css, rungit reset Head style.cssto unstage it.Caution: Using
git reset --hardcan permanently delete changes.
git revert
It creates a new commit that undoes the changes changes of a specified commit, preserving the project history.
Usage:
git revert <commit>Example: To undo the effects of a problematic commit, first identify its commit hash using
git log, then rungit revert <commit-harsh>.Note: It is safe for undoing changes in shared repositories, as it doesn't alter the commit history.
Visualization of the Git Workflow
[Start]
|
v
[Working Directory]
|
v
[git status] ---> [git add <file>] ---> [git commit -m "message"] ---> [git push origin main]
|
v
[Staging Area]
|
v
[Local Repository]
|
v
[Remote Repository]
A Practical Workflow
Create a hospital data model.
Step 1: Start project
git init
Initialize Git inside the project folder.
Step 2: Check changes
git status
Git identifies modified datasets and scripts.
Step 3: Stage completed work
git add scripts/
git add README.md
Step 4: Save a checkpoint
git commit -m "Add patients age"
Step 5: Upload to GitHub
git push origin main
Importance of Git in data science
It provides several practical benefits beyond version control.
Reproducibility:
Every step and model update is recorded.Experiment Tracking:
Compare different feature engineering or model versions.Collaboration:
Multiple analysts can contribute without overwriting each other's work.Backup:
Project remain safe even if a local computer fails.Documentation:
Commit history tells the story of how the project evolved
Essential Git commands
git init -Initialize a Git repository
git status - Check modified and staged files
git add - Stage all changes
git add filename - Stage a specific file
git commit -m "message" - Save a project checkpoint
git log --oneline - View commit history
git pull origin main - Download latest changes
git push origin main - Upload commits to GitHub
.gitignore - It is used to stop certain files from committing automatically. Should automatically be in a repo when creating a project.
Tips
- Use git status frequently to understand what's changed.
- Stage only what you what to commit. git add -p enables selective staging of file changes.
- Write clear commit message to document why changes were made.
- Commit often, but meaningful.
Conclusion
The Git workflow is a simple but powerful process that moves changes through stages ( working Directory --> Staging Area --> Commit --> GitHub) for collaboration and backup. For data scientists, this workflow ensures the experiment remains organized, reproducible, and easy to manage throughout the project lifecycle.
Mastering these four stages builds a strong foundation for collaborative analytics, machine learning development, and and professional software engineering practices in data science.
As i finish let me leave you with
"The journey of a thousand miles begins with a single step."
-Lao Tzu


Top comments (0)