ud788 »

Git Tips for UIKit Fundamentals

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:

Scenario 1. "I’ve finished implementing the code for step42.1. Now I’d like to checkout the branch for step42.2"

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:

  1. 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”

  2. 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.

Scenario 2. "I accidentally tried to push to the course repository."

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!

Scenario 3. "I tried to checkout the branch for the next step of the lesson, but I got an error message."

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.).