LESSON 6: GITHUB & GIT
INTRODUCTION
In the past few lessons you have developed your own character. In this final lesson you are going to release your character into the environment. This is done using GitHub, so the first thing you have to do is create an account on GitHub.
GitHub is a website where you can save so-called git repositories. A git repository, simply put, is a collection of files, and different versions of them are maintained. GitHub makes it easy to put code online, collaborate with other developers and contribute to open-source projects. The next thing you do is download the GitHub app for Mac or for Windows. Do you work with Linux? Various GUI tools are available, such as gitk, but if you are already used to the command line interface it is advisable to use git from the command line. This, by the way, is also possible for Mac and Windows. If you would like to know more about Git, this online book is an excellent reference. In this lesson we will only address Mac and Windows, but there are many good tutorials on git and GitHub on the internet (for instance, this one).
Git is a revision control system (Wikipedia). The short version is that you can save different versions of files. They may be text files, Processing sketches, images, 3D-models, and, well, any other type of file. One of the biggest advantages of revision control systems is that you can go back to a previous version of your project at any given moment. So you could experiment with a new piece of code without having to worry that you are going to ruin anything. You never have to copy another folder and save it as ‘project_1.9’ or something similar; git keeps track of everything for you.
After you create a repository or project, the workflow looks something like this:
Make a change to your code
Record the changes in a commit
Repeat steps 1 and 2 for as long as you need
Push the commits to GitHub (or another server such as Bitbucket or your own server)
STEP 1
After you install the GitHub app you can log in with your newly created GitHub account. Log in using your login. Then enter your name and e-mail address, these will be added to all your je commits.
Mac users: If you have not installed git previously or if you are unsure, click on ‘Install Command Line Tools’. If the wizard indicates that git has already been installed, click ‘skip’.
STEP 2
Now that you have completed your set-up you can start making your first repository. In the top left corner of your screen, click the plus-icon and fill in the name of the repository and the folder in which you want to save your repository. Click on ‘create repository’. Now open in the folder you have just entered using Finder or Explorer (or click on the repository with your mouse and select ‘Show in Finder’/‘Open in Explorer’).
STEP 3
Now create a new text file, copy your character code to it, and save it as ‘Classname.pde’ in the repository folder, where you replace 'Classname' by the name of your class. It's a good idea to use your own name as part of the creature classname to prevent collisions with other creatures in the environment.
Mac users
Are you working in TextEdit on a Mac? Go to the Format menu and click on ‘Make Plain Text’ to remove all layout and styling.
If you open the GitHub app now, you will see that the program detects your change; you have added a file. (Windows: click on ‘Show’ next to ‘Uncommitted changes’.) Now, go to ‘Summary’ and enter a short description of what you have done, for instance, ‘Added the character file’. In ‘Description’ you can add a more extensive description, but you can also leave this empty. Make sure ‘Select all’ is checked, and click on ‘Commit’ (Windows: ‘Commit to master’) to create a new commit. You have now committed the change.
STEP 4
To make the repository available in GitHub, click ‘Publish’ in the top right hand corner (Windows: ‘Publish Repository’). The first time you do this you have to enter the name of the repository (the name on GitHub does not have to be the same as on your own computer) and a description of the repository. You could fill in: 'This repository holds my character for the Play&Learn course by FIBER and MU. See http://playnlearn.codedmatters.com for more information.' Now click on ‘Push Repository’ to complete the process. If you go to GitHub and log in you will see that a repository has appeared in your name. Click on the name to view the repository. You can now view the .pde file and the commit you have just pushed. If you add more commits, you can also view all versions of your files.
STEP 5
You are almost ready to add your creature to the environment. Before you upload your creature, make sure your creature class has the class 'Creature' as its superclass: class MyAwesomeCreature extends Creature { … }