Creating a Branch for Homework Assignments

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Screenshot of GitHub Desktop Current Branch Drop Down form
Screenshot of GitHub Desktop Current Branch Drop Down form

Click the Current Branch drop-down as indicated in the screenshot above. Next, click the New Branch button.

Screenshot of GitHub Desktop Create Branch form
Screenshot of GitHub Desktop Create Branch form

A dialog will appear where you provide a name for the branch to be created. Note that under the name field, there is some text letting you know that the branch will be based on your currently checked-out branch. In this case, the main branch. When making branches for homework, you always want to make sure that the new branch is created based on the main branch.

The branch name should be descriptive of the work contained in the branch. In our case, our branches are responsible for holding the work for each week, so the name ‘week-1’ will be suitable for our homework this week. We can continue this naming convention for each of our homework branches. You are free to use any naming convention you wish for your branch names, but keep in mind that spaces are not valid characters in branch names. Click the blue Create Branch button after providing a name for your branch.

Screenshot of GitHub Desktop after create branch new branch is current branch
Screenshot of GitHub Desktop after create branch new branch is current branch

These steps are the equivalent of making sure you are the main branch, create a new branch, create folder in the repository folder.

# verify current branch
git branch 

# switch to main branch if necessary
git switch main

# create branch 
git switch -c week-1

# make folder for assignment. You create this folder in the repository folder
mkdir week-1

After the branch is created, you will notice that the GitHub Desktop screen has changed again. The Current Branch drop-down shows week-1, the Publish Branch button replaces Fetch Origin, and there is now a Publish Branch button in the main window. We will publish the branch later after we are complete with our homework. Click the Show in Finder button in the main window.

Screenshot of Finder open to repository folder with menu drop down
Screenshot of Finder open to repository folder with menu drop down

A Finder window will appear with the folder highlighted that has the name of the repository. Click the button with the “…” that is to the left of the search button (🔍) in the top right corner and select New Folder in the drop-down. This will create a new folder called “untitled folder”.

Screenshot of Finder open to repository new folder created
Screenshot of Finder open to repository new folder created

Your finder window should look like the following screenshot. Rename the folder to “week-1” or what ever you named your branch.

Screenshot of GitHub Desktop Repository info screen. Changes detected
Screenshot of GitHub Desktop Repository info screen. Changes detected

In GitHub Desktop, you may notice that changes have been detected. There is a new file called .DS_Store. The file .DS_Store is a hidden file used by Finder to store folder-specific metadata. We do not need to track this file in our repository, so we will need to instruct Git to ignore it. Go back to the Finder window where you created the directory in the last step.

Select the folder that has the name of the repository and press Command + Shift +. (period) to show the hidden files and directories.

Screenshot of Finder open to repository new folder created
Screenshot of Finder open to repository new folder created

Hidden files and folders will appear in light gray. Double-click on .gitignore to open the file in TextEdit. Add .DS_Store to the file above line ## User Settings and save the file. You can close TextEdit

Screenshot of TextEdit with the gitignore file open
Screenshot of TextEdit with the gitignore file open

In GitHub Desktop, note that the change to .DS_Store has been removed as Git is now ignoring it. There is still one change, and that is the change we made to .gitignore.

Screenshot of GitHub Desktop Repository info screen after editing gitignore
Screenshot of GitHub Desktop Repository info screen after editing gitignore

In the lower left of the window, there are two text fields and a button. Here we will perform our first commit. The field with the placeholder “Update .gitignore” is the summary field and is required to commit. Description is optional and is used to hold more detailed information about the changes, if necessary. In the summary field type “updated .gitignore” and click the blue “Commit to week-1” button.

GitHub Desktop will update to reflect that there are no local changes and provide buttons to publish the branch to GitHub. Do not publish at this time.

These steps are equivalent to staging the changes to .gitignore and committing those changes.

git add .gitignore
git commit -m "added .DS_Store to git ignore

Let’s review what we have done.

  • Created a branch for this week’s homework
  • Created a folder in our repository to hold the work for this week
  • Edited the .gitignore file to tell Git to ignore files named .DS_Store
  • Made our first commit.

In the next section we will add a Xcode project to our repository.

See forum comments
Download course materials from Github
Previous: Setting Up GitHub Desktop & Creating Our First Repository Next: Adding an Xcode Project to the Repository