Single logo
  • Courses
  • Blog
  • About
Join for freeJoin free
Learning pathShip Your First Model: From Notebook to a FastAPI Service
  1. 1
    Saving and Loading Models with joblib: One Pipeline, One File
  2. 2
    FastAPI Hello World: Routes, uvicorn and the Free Swagger Page
  3. 3
    Deploy a Machine Learning Model with FastAPI: POST /predict for a Saved Model
  4. 4
    Project: Car Price Predictor End to End, from CSV to a FastAPI Price API
  5. 5
    Python Virtual Environments: One Project, One Toolbox
  6. 6
    Git and GitHub Fundamentals: Commits, Branches, Push and Pull
  7. 7
    Testing a FastAPI App with pytest: Three Small Tests
  8. 8
    Config and Logging Instead of Hard-Coded Values in ML Training
  9. 9
    SQL Essentials for Python: SELECT, WHERE, JOIN and GROUP BY
  1. Blog
  2. /
  3. Machine Learning
  4. /
  5. MLOps and Production ML

Learning path: Ship Your First Model: From Notebook to a FastAPI Service · Step 6 of 9

Git and GitHub Fundamentals: Commits, Branches, Push and Pull

The Git you use every day, on a tiny hello-ml project: commits as save points, the staging area, a branch merged with a fast-forward, then push, clone, pull and pull requests with a teammate.

Chaand Sheikh

·27 November 2026Engineering Basics

What you will learn

  • Explain a commit as a save point and the difference between Git and GitHub
  • Make a first commit with git init, git status, git add and git commit
  • Try an idea on a branch and merge it back with a fast-forward
  • Share work with git remote, push, clone and pull, and know what a pull request is

Before you start

  • Running commands in a terminal
  • Python Virtual Environments: One Project, One Toolbox

Without Git, a project folder slowly turns into this: train.py, train_v2.py, train_final.py, train_final_REAL.py. Which one is the latest? Nobody knows.

With Git, you keep one file, and Git keeps the history for you. Every change is saved, with who made it and why. That's problem one solved.

Problem two is the team. Jack, Emma and Liam work on one project. Instead of emailing zip files around, they share one copy on GitHub.

  • Git is the tool on your laptop. It records the history.
  • GitHub is a website that keeps the shared copy for the team.

Our example is a tiny project called hello-ml, with a README.md and one training script:

def train():
    print("Training the model...")


if __name__ == "__main__":
    train()

A commit is a save point

Think of a video game. You save before the hard level, and if it goes wrong, you load the save. A commit is a save point for your code: a snapshot of the files, with who, when and why.

Jack makes three save points on this project. Git gives each one a short id:

A chain of save points f8e1e04 c851f06 0b0e3a4 First version Add a fixed seed Add how to run HEAD you can go back to any save point
The history is a chain of commits. Each one is a full snapshot with its own id, so you can always go back to an earlier one.

Your first commit

Tell Git who you are

Once per laptop, set your name. It goes into every commit you make. (Git also wants your email, set the same way with user.email.)

git config --global user.name "Jack Miller"

Start the history

Inside the project folder:

git init
Initialized empty Git repository in C:/code/hello-ml/.git/

The whole history now lives in a hidden .git folder inside the project.

See what changed

git status --short
?? README.md
?? train.py

Two question marks mean new files that Git isn't tracking yet.

Stage, then commit

git add .
git commit -m "First version"
[main (root-commit) f8e1e04] First version
 2 files changed, 9 insertions(+)
 create mode 100644 README.md
 create mode 100644 train.py

git add . picks the changes and puts them in the staging area. git commit -m saves everything staged as one snapshot, with a message saying why. That's our very first save point, f8e1e04.

Working folder, staging area, history Working folder the files you edit Staging area picked for the next save .git history saved snapshots git add git commit git status shows what is in each place
git add picks changes for the next save point. git commit saves what was picked as one snapshot in the history.

Read the history

git log --oneline
f8e1e04 (HEAD -> main) First version

HEAD -> main means: this is where you are right now, on the branch called main.

Try it on a branch, then merge

What if you want to try something without breaking the working code? Make a branch. A branch is a safe place to experiment, and main stays as it is.

git switch -c seed
Switched to a new branch 'seed'

Jack adds a fixed seed to train.py:

SEED = 42


def train():
    print(f"Training the model with seed {SEED}...")


if __name__ == "__main__":
    train()

and commits it. -am stages every tracked file that changed and commits in one step:

git commit -am "Add a fixed seed"
[seed c851f06] Add a fixed seed
 1 file changed, 4 insertions(+), 1 deletion(-)

This commit lives on the seed branch only. Happy with it? Go back to main and merge:

git switch main
git merge seed
Updating f8e1e04..c851f06
Fast-forward
 train.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Git says fast-forward. Why? Because main had nothing new of its own since the branch started, so Git simply moves the main label forward to the seed commit.

git log --oneline
c851f06 (HEAD -> main, seed) Add a fixed seed
f8e1e04 First version

Both commits are now on main. Jack then adds a "how to run" line to the README and saves a third time:

git commit -am "Add how to run"
git log --oneline
0b0e3a4 (HEAD -> main) Add how to run
c851f06 (seed) Add a fixed seed
f8e1e04 First version

main has moved on, and the seed label stays where the branch ended.

Your laptop, GitHub, and a teammate

So far, everything lives on Jack's laptop. Now the code goes to GitHub. On GitHub, Jack creates a new repository, keeps it empty, and copies its address. GitHub's docs page "Creating a new repository" walks you through it.

The commands below are shown without output, and the address is a placeholder for your own repository's address:

# Jack: connect the project to GitHub, then upload
git remote add origin https://github.com/<your-name>/hello-ml.git
git push -u origin main

# Emma: get her own full copy, history included
git clone https://github.com/<your-name>/hello-ml.git

# Emma changes something, commits it, and uploads it
git commit -am "<what she changed>"
git push

# Jack: bring Emma's commit down to his laptop
git pull
  • origin is just a short nickname for the GitHub address.
  • -u on the first push remembers where to push next time, so later it's just git push.
  • git clone gives Emma the files and the whole history.
Commit, push, clone, pull Jack's laptop commit saves here GitHub shared copy Emma's laptop full copy too push pull clone push
Commit saves on your laptop, push uploads to GitHub, pull downloads what others pushed. That's most of Git.

Many people, one project

  1. Everyone has a full copy. Each laptop has the whole history, so nobody waits for anybody.
  2. The owner decides who can push. You invite people with read or write access.
  3. A pull request asks before merging. You push your branch and ask, "can I merge this?" A teammate reviews it, and then it gets merged. GitHub's docs call it a proposal to merge code changes.
  4. Conflicts are normal. If two people change the very same line, Git marks that line, you pick what stays, and you commit.

GitHub isn't the only host. GitLab and Bitbucket work the same way, and GitLab calls a pull request a merge request.

Common mistakes

  • Keeping train_final_REAL.py copies. One file, many commits. The history is the version list.
  • Experimenting on main. Switch to a branch first, so the working code stays safe.
  • Starting work without pulling. Pull first, so you build on your teammates' latest commits.
  • Committing the toolbox. The .venv folder stays out of Git; commit requirements.txt instead (see virtual environments).

Recap

IdeaCommandIn one line
Commitgit add . then git commit -m "..."A save point
Branchgit switch -c seedTry an idea safely
Mergegit switch main then git merge seedBring the idea back into main
Push / pullgit push, git pullSend your work up, bring others' work down
Pull requeston GitHubAsk for a review before the merge

The daily loop is simple: commit often, push when it works, and pull before you start.

Try it yourself: make a folder, run git init, commit twice, then try a branch and merge it back. Check each step with git log --oneline.

Built this? Share your solution in the StudyEasy AI Community.

Join free on Skool →
← Previous
Python Virtual Environments: One Project, One Toolbox
Next →
Testing a FastAPI App with pytest: Three Small Tests
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool
Go deeper with a course

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)

Related articles
Python Virtual Environments: One Project, One Toolbox

Why every Python project gets its own virtual environment: two projects that need different versions of requests, python -m venv .venv, activation, pip install and the PyCharm setting that activates it for you.

Testing a FastAPI App with pytest: Three Small Tests

A tiny FastAPI app with a Hello World route and a name route that refuses numbers, three pytest tests that check it, and what happens when the validation is deleted by mistake.

Config and Logging Instead of Hard-Coded Values in ML Training

Take the hard-coded values out of a car price training script: one config.toml read with tomllib, logging with levels and a run id on every line, and secrets read from the environment. Same RMSE, 2195, before and after.

SQL Essentials for Python: SELECT, WHERE, JOIN and GROUP BY

The SQL a Python developer needs, on a tiny shop with four customers and eight orders: CREATE TABLE, INSERT with placeholders, SELECT with WHERE, JOIN, GROUP BY, pandas.read_sql, and why values never go in f-strings.

On this page
  • A commit is a save point
  • Your first commit
  • Tell Git who you are
  • Start the history
  • See what changed
  • Stage, then commit
  • Read the history
  • Try it on a branch, then merge
  • Your laptop, GitHub, and a teammate
  • Many people, one project
  • Common mistakes
  • Recap
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool
Go deeper with a course

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.