Skip to content

Week 6: Git, GitHub, and your first project

~10 min

This week's goal

This week you start keeping your work in version control. You install git, record your changes as commits, and push the project to GitHub. You also build your first real program, the command-line expense tracker from the Python course. The tracker is the first of the course's capstone projects. It uses everything from Parts 1 to 4.

The main texts are the git and GitHub page and Capstone 1: a command-line expense tracker.

Day-by-day (about 1.5-2 hours per day)

Day 1. Read the git and GitHub page up to the section on the basic commands. Install git if you do not have it, and check it with git --version. Set your name and email with git config --global user.name and git config --global user.email. Create a free GitHub account if you do not have one. Read about git for the overview.

Day 2. Read chapter 1 of Pro Git, focusing on the idea that git stores snapshots of your files. In your course folder, run git init, add hello.py with git add, and make a commit with git commit -m "Add hello script". Run git status and git log after each step, and write down what each command showed.

Day 3. Read the capstone's requirements and acceptance checks, and the suggested file layout. Make a new folder expense-tracker and put it under git. Work through milestones 1 and 2: the command loop, and parsing one add command. Commit after each milestone with a short message. A commit should describe one change.

Day 4. Work through milestones 3 and 4: store expenses as dictionaries, then save and load them with json. Test the save by running the program, adding an expense, quitting, and listing the expenses again after you start it. Commit when this works. If it does not, use git diff to see what changed since the last commit.

Day 5. Work through milestones 5, 6, and 7: listing, totals, deletion, and the error paths. Run the acceptance checks from the capstone table one at a time, starting with requirement 1. Keep a check mark next to each requirement that passes. You do not have to finish all eleven today, but do not skip any.

Day 6. Finish the remaining checks. Write a README.md with what the program does, how to run it, and the commands it accepts. Create an empty repository on GitHub with the quickstart steps, connect it to your local folder, and push your first branch. Depending on your git version it is called main or master; run git branch to see which one you have. Open the repository in the browser and check that the README shows and that the code is there.

Day 7 is a rest day.

Deliverable

A GitHub repository named expense-tracker that holds expense.py, a README.md, and a commit history of at least five commits with clear messages. The program passes all eleven acceptance checks in the capstone table. Put the repository link in your notes, because you will use it in week 12.

Check yourself

  1. What is the difference between git add and git commit?
  2. What does git status tell you?
  3. Why does the capstone ask you to save data in expenses.json and not only in memory?
  4. What is a remote, and what does git push send to it?
  5. Why is one commit per change easier to review than one large commit?
Answers
  1. git add stages a change so the next commit includes it. git commit saves the staged changes as a new snapshot in the history.
  2. It lists which files are changed, which are staged, and which are untracked. Run it often to see the state of your folder.
  3. A program that keeps data only in memory loses it when it stops. Saving to a file lets the expenses survive a restart, which is requirement 9 of the capstone.
  4. A remote is a copy of the repository on another server, such as GitHub. git push sends your commits to that remote.
  5. A small commit shows exactly what changed, so you can find a bug by looking at one commit. A large commit mixes several changes, and it is harder to read and to undo.

Sources