Git

Even more important this semester

Version control

  • Keeps track of the history of changes

  • Allows branching of history

  • Lets us compare different branches.

  • Helps to merge branches back together

Normal development cycle

  • Make a feature branch

  • Make changes to files

  • Periodically commit changes to branch

  • Push (sync) branch to Github

  • Make a PR and request review

  • After PR approved, merge to main

  • Optionally, delete the feature branch

What is a branch?

  • A named version of all the files in your repository

  • Different branches can have different contents

  • Allows you to work on different things without them interfering with each other.

  • In multi-person projects even more important.

Commits

  • Commits are how you save work in git.

  • You might make several changes in multiple files before you commit them.

  • Each time you make a commit, you will write a short description of the commit.

  • Each new commit is added to the current branch.

Some commit messages

A special branch: main

  • The main branch is what its name says.

  • Ultimately we want all the code you write to end up in main.

  • But code starts out in “feature branches”

Merging

  • Merging is the process of adding the commits made in one branch (usually a feature branch) to another branch (usually main.)

  • If the changes don’t textually conflict, things merge automatically

  • That should almost always be the case for you.

Pull requests

  • A Github feature for looking at the changes you’ve made on one branch that you want to merge into another.

  • Allows reviewing, commenting, approval, etc.

  • The main mechanism for communicating about code in open source projects and many companies.

  • And in this class.

Our branch naming convention

  • Name branches for the directory where the new code will live e.g. projects/whatever

  • This ensures that code from the projects/whatever branch will never conflict with code from other project branches.

Continuing work on a feature branch

  • After you merge your feature branch PR to main you can keep working on the same branch if you don’t delete it.

  • Or you can create a new branch with the same name if you did.

  • New PRs will only include the new changes.

Git guidelines

  • Submit PRs for review regularly.

  • Merge PRs as soon as they are approved.

  • If I request changes, you should work on those things and re-request review.

  • Delete old branches when you are done with a project or putting it down for a while.

  • Don’t work on too many projects at once. Ideally one at a time.

This semester

  • You will spend more time working on projects than on problem sets.

  • To do your work you will have to deal with git and Github.

  • We are going to start using a new development environment called Codespaces that is provided by Github.

But first

Spring cleaning