Python · Intermediate level

Intermediate level · Module 6: Python Intermediate Project Studio · Lesson 1 of 3

Version Control with Git

Record project history in small, well-described commits and undo mistakes safely.

In this lesson you will

  • Initialise a repository and commit changes
  • Write useful commit messages and use .gitignore

Key concepts

repositorycommitstaging area.gitignore

The lesson

Git records the history of a project as a series of commits — snapshots with a message explaining what changed. You can see who changed what, compare versions and return to an earlier state if something breaks.

The basic cycle is: edit files, git add the changes you want to record, git commit -m "Explain the change". Small commits with clear messages make history useful.

A .gitignore file lists what must never be committed: the virtual environment, data files with personal information, passwords and generated output.

Step by step

  1. Run git init in your project folder.
  2. Create a .gitignore that excludes .venv and data files.
  3. Commit your current work with a clear message.
  4. Make a change, view it with git diff, and commit again.
Workflow

The everyday Git cycle

The four steps you repeat many times a day to keep a clean, useful project history.

  1. Edit

    Change code in small, focused steps.

    Your editor

  2. Review

    git status and git diff show exactly what changed.

    git status / git diff

  3. Stage

    git add the changes that belong together.

    git add

  4. Commit

    git commit -m "Explain why the change was made".

    git commit

  5. Share

    git push to GitHub; teammates git pull.

    git push

Repeat the cycle for each small change. Small commits make it easy to find and undo mistakes.

Why it works

Never commit the .venv folder, passwords or files with personal data — list them in .gitignore before the first commit.

Practice activity

Put your project under Git with at least six meaningful commits and a .gitignore that excludes the venv and data files.

Expected result: A repository with a clean history and no venv or data files committed.

Check your understanding

  1. Why exclude data files containing names and phone numbers from Git?

    Show answer

    History is permanent and repositories are shared; personal data must not be exposed.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.