I11 · Intermediate Capstone: An End-to-End AI Project

Version Control with Git and GitHub

Version control records every change to a project's files so you can see history, go back to earlier versions and work on changes in parallel. Git, created by Linus Torvalds in 2005, is the most widely used version-control system; it stores snapshots called commits in a repository. Branches let you develop a feature without disturbing the main version, and merging brings the work back together. GitHub, founded in 2008 and owned by Microsoft since 2018, hosts Git repositories online and adds collaboration tools such as pull requests, code review, issues and automated checks.

15 min Intermediate · Sublevel Advanced Jump to the activity

What you need: The earlier topics of this module.

Definition

"final_model.py", "final_model_v2.py", "final_model_v2_REALLY_final.py"... and you still cannot find the version that worked last Tuesday. Version control solves this, and it is how every software and AI team in the world works together.

Version control records every change to a project's files so you can see history, go back to earlier versions and work on changes in parallel. Git, created by Linus Torvalds in 2005, is the most widely used version-control system; it stores snapshots called commits in a repository. Branches let you develop a feature without disturbing the main version, and merging brings the work back together. GitHub, founded in 2008 and owned by Microsoft since 2018, hosts Git repositories online and adds collaboration tools such as pull requests, code review, issues and automated checks.

In simple words

Git is like a time machine and save-game system for your project. Every commit is a saved point you can return to. Branches are like trying a different route in a game without losing your main progress.

Overview

  • Version control records every change to your files so you can review, undo and share work.
  • Git, created by Linus Torvalds in 2005, is the most widely used version-control system.
  • GitHub is a website that hosts Git repositories and supports collaboration.
  • Core commands are git init, add, commit, status, log, branch, merge, push and pull.
  • A .gitignore file keeps large data, secrets and temporary files out of the repository.
  • A public GitHub repository works as a portfolio for students and job seekers.

Why it matters

Version control prevents lost work, shows exactly what changed and when, lets teams work together without overwriting each other and makes results reproducible by linking them to a specific commit. A public GitHub profile is also a portfolio employers look at.

Key terms

Repository
A project folder whose full history Git tracks.
Commit
A saved snapshot of changes with a message explaining them.
Branch
A separate line of development, such as a branch for trying a new model.
Merge
Combining changes from one branch into another.
Pull request
A GitHub request to merge a branch, where teammates review the changes first.
.gitignore
A file listing things Git should not track, such as large data, secrets and temporary files.

Types

Git and GitHub work involves several types of concept and workflow.

1. Repositories and commits

A repository is a project folder tracked by Git; a commit is a saved snapshot of changes.

  • How it works: git add stages changes and git commit -m "message" saves them with a description; git log shows the history.
  • Example: Commit messages such as "Add median filling for missing prices".
  • When to use it: Use small, frequent commits with clear messages so problems are easy to find and undo.

2. Branches and merging

Branches are separate lines of work; merging combines them.

  • How it works: git branch and git switch create and move between branches; git merge brings changes back; conflicts are resolved by editing the marked lines.
  • Example: Trying a new model on a branch called try-xgboost without breaking the main code.
  • When to use it: Use branches for every experiment or feature, keeping main working.

3. Remotes: push, pull and clone

Copies of the repository on a server such as GitHub.

  • How it works: git push uploads commits, git pull downloads others' changes and git clone copies a repository to a new computer.
  • Example: Pushing a project from a school computer and pulling it at home to continue.
  • When to use it: Use them to back up work and to collaborate.

4. Pull requests and code review

A GitHub feature for proposing changes and discussing them before merging.

  • How it works: Push a branch, open a pull request, teammates comment and approve, then it is merged.
  • Example: A teammate spotting data leakage in a pull request before it reaches main.
  • When to use it: Use it in team projects to catch mistakes and share knowledge.

5. Good repository practices

Habits that keep a repository clean, safe and easy to use.

  • How it works: Use a .gitignore, never commit passwords or API keys, store large data elsewhere, add a README and a licence, and tag releases.
  • Example: Adding .env and data/raw/ to .gitignore so keys and large files stay private.
  • When to use it: Use them from the first commit; removing a leaked secret from history is hard.

Explained in detail

The everyday Git workflow

CommandWhat it does
git initStarts tracking a folder as a repository
git clone <url>Copies an existing repository, for example from GitHub, to your computer
git statusShows which files changed and what is staged
git add model.pyStages a change to be included in the next commit
git commit -m "Add wind forecast feature"Saves a snapshot with a clear message
git switch -c try-random-forestCreates and moves to a new branch
git push / git pullSends your commits to GitHub / brings others' commits to you
git log --onelineLists the history of commits

Working as a team on GitHub

A common team workflow keeps the main branch always working. To try an idea, such as adding a festival feature, a team member creates a branch, commits small, clear changes, pushes the branch to GitHub and opens a pull request describing what changed and the validation results. A teammate reviews the code, asks questions and suggests improvements; automated checks can run tests. When everyone is satisfied, the branch is merged into main. Issues track bugs and tasks, such as "Alert SMS missing Hindi text", and can be linked to the pull requests that fix them. If two people change the same lines, Git reports a merge conflict, which is resolved by choosing or combining the changes and committing again.

Git for AI projects

  • Commit code, documentation, small configuration files and the experiment log; do not commit large data sets or model files directly, which Git handles poorly.
  • Use .gitignore for data folders, virtual environments and secrets; store large data in cloud storage or with tools such as Git LFS or DVC.
  • Never commit API keys or passwords; if one is committed, consider it leaked and replace it immediately, because history keeps it.
  • Record the commit ID with each experiment's results so you can always return to the exact code that produced them.
  • Write commit messages that explain why, not just what: "Lower alert threshold to 80 after principal feedback".

You do not need to memorise every command. Editors such as Visual Studio Code and the GitHub Desktop app show changes, commits and branches visually, which is a gentle way to start. Learn the core loop first, change, add, commit, push, and look up the rest when you need it.

How it works

  1. Create a repository and a .gitignore for data, environments and secrets.
  2. Commit small, meaningful changes with clear messages.
  3. Use a branch for each new idea or feature.
  4. Push to GitHub and open a pull request for review before merging.
  5. Link experiment results to commit IDs and keep main always working.

Try it yourself

Adding a feature with Git and GitHub

Put the steps in order.

  1. 1Push the branch to GitHub
  2. 2Merge into main
  3. 3Teammate reviews and approves
  4. 4Create a branch for the new feature
  5. 5Make changes and commit with clear messages
  6. 6Open a pull request with results

Commit it or ignore it?

Should each item go into the Git repository?

  • A file containing the SMS API key

  • The data-cleaning script

  • The README and model card

  • A 4 GB folder of raw sensor files

  • requirements.txt

Common mistakes

  • Making one huge commit at the end of the project.
  • Committing data sets, model files or secrets.
  • Working directly on main without branches or review.

Check yourself

Question 1

1. What is a commit?

Question 2

2. Why use a branch to try a random forest?

Question 3

3. You accidentally pushed an API key to GitHub. What should you do?

Summary

  • Git records project history in commits; branches and merges allow safe parallel work.
  • GitHub adds pull requests, reviews and issues for teamwork and is a public portfolio.
  • Commit code and documentation, ignore data and secrets, and link results to commits.

Finished reading?

Sources: Scott Chacon and Ben Straub, Pro Git (free online book) · GitHub Docs: getting started