Throughout the course, git will be our primary means of sharing code between students and instructors. The course has a repository, and each branch in that repository represents a different step within a lesson.
Here are some scenarios you may encounter:
error: Your local changes to the following files would be overwritten by checkout: BirdSong/BirdSong/SongViewController.swift Please, commit your changes or stash them before you can switch branches.
If you try to checkout step42.2 and you get a message like this, it means you need to clear your working directory.
At this point, you have two options:
If you’ve written some code that you’d like to keep, commit that code to a new branch in your local repository.
Let’s say I’m on the branch step42.1-birdSongApp. First I make a new branch:
git branch step42.1-birdSongApp-gm
Then I add and commit my recent changes to the new branch:
git add .
git commit -m “implementing Woody Woodpecker modification for birdsong playback”
If you’re not that attached to the code you just wrote you can discard the changes in your working directory:
git checkout — .
Both options leave you with a clean working directory and put you in the right position to checkout the branch for the next step.
*Note. Okay, there are probably a lot more than 2 options, including stashing your recent changes. Learn more about stashing here.
You’ll never need to push to the course repositories, but don’t worry, the course repositories are set up so that students can’t push to them.
We do encourage you to make a remote repository of your own on github and use it to showcase your work!
error: pathspec 'step42.1-BirdSangApp' did not match any file(s) known to git.
If you get an error message like this, one way to troubleshoot is to look at a list of all of the branches in the current remote repository using the following command:
git branch -r
This is a way to double check that the branch with the name you are using does indeed exist (no typos etc.).