Create GitHub repo for your code examples using Windows

This note helps you create a GitHub repository to hold your course’s programming code examples, when programming on a Windows PC.

.

Scenario

You teach a programming course.

You want to publish code examples. Easily.

Well, a GitHub repository can be a useful tool.

.

Assumptions

You are using a Windows PC to write code.

You have a GitHub account. The “free” account is fine. In that situation, your code will be public. EVERYONE can view it (because it’s on the web).

For this document, we’ll assume that you are using Visual Studio. (That’s notable, because your .gitignore file contents will be tuned accordingly.)

Also, for this document, we’re working with ASP.NET projects. An ASP.NET project includes a “packages” folder, with dlls needed for a specific project. This folder is large, about 30MB to 70MB.

So, we will permit a top-level (i.e. ‘root’ directory) “packages” folder, but will ignore each individual project’s “packages” folder. (We don’t want the repository size to balloon needlessly.) When a student downloads a project (or all projects), they’ll simply have to cut/copy-paste the top-level “packages” folder to a specific project. That way, the specific project will build and run successfully.

Also, you must have the GitHub for Windows app installed on your computer. (There’s probably direct Visual Studio integration, but I have opted to manage the commit/sync process myself.)

.

How to organize your code on your computer

You need a folder to hold your projects. For example, I created the following folder for my BTI420 course:

~/BTI420/Projects

In that folder, I create my projects. During a semester, it’s possible to accumulate thirty or forty projects.

My philosophy is to treat the projects in that folder as works-in-progress.

Next, in that folder, I have a GitHub folder. (It gets created by following the steps in the next section.) I treat that as a final ‘published’ destination, that holds a copy of the work-in-progress project. In other words, I don’t actively edit/update the projects in the GitHub folder.

Philosophically, this works for me, because the code examples are just that – code examples.

If I was publishing a project that WAS intended to be a work-in-progress, soliciting student (and public) input, then I would use it as a true GitHub repository, with all its features and benefits.

.

Then, each week, I create a named folder for the week. Each weekly folder will hold code examples, and a README.md file. For example:

~/BTI420/Projects/GitHub/Week_01

~/BTI420/Projects/GitHub/Week_02

.

Use GitHub for Windows to create a repository

After installing GitHub for Windows, and configuring it with your account information, you can create a repository.

Click the “create” button/link near the top of the panel.

Fill in the fields. Take care, and think about what you’re doing. Here’s a sample screen shot:

github-for-windows-create-repo

.

This will create the “bti420winter2014” folder under the “~/BTI420/Projects/GitHub” folder.

FYI – after publishing to GitHub, the public URI will be:

https://github.com/peteratseneca/bti420winter2014

.

Using (Windows) File Explorer, go to (open) the GitHub folder. You will see two files, .gitattributes and .gitignore.

Edit the .gitignore file. Replace its contents with the contents of my .gitignore file found at the URI above.

Next, add LICENSE and README.md files. You can copy them from

Then, add a “Week_01” folder, to hold your week-1 code examples. In that folder, create a README.md file. You can use the contents of any of my weekly “README.md” files as a template if you wish.

.

What’s with Markdown?

Markdown is the markup language used for various GitHub assets.

Read about it and learn it by using docs provided by the author, John Gruber.

.

Publishing your first project

Assume that you have finished a project, and are ready to publish it.

Copy the project folder, and paste it into Week_01.

Edit/update the Week_01 “README.md” file with suitable information about the code example(s)  for the students’ benefit.

Then, copy the project’s “packages” folder and paste it to the repository root, alongside the Week_01 folder etc. At this point, the contents of the “~BTI420/Projects/GitHub/bti420winter2014” folder should include these assets:

github-for-windows-repo-start-filesystem

Open GitHub for Windows. Select the repository. It will show you a list of uncommitted changes.

Fill in the “Commit Message” in the upper-left area:

github-for-windows-add-first-project

.

Click the “commit to master” button. Next, click the “sync” button in the upper-right area. See the screenshot:

github-for-windows-add-first-project-sync

.

After a few seconds or minutes, your repository is posted to GitHub on the web.

github-on-the-web-repo

.

Uh oh – no packages folder?

You may have to do one more thing.

In GithHub for Windows, click the tools (gear) icon in the upper-right, and choose “open a shell here”.

Type this command in the shell:

git add -f packages

Then, you can exit the shell.

Save/commit, and then sync. Life will be good again.

.

.

.

.

.

.

.

.

.

.

.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: