Github Tutorial

This tutorial will focus on using github through the github desktop app using a renpy game as an example.

TOC

How to Github??????

First things first, if you don't have a github account yet, make one at github.com and just select the free individual tier. If you want

Then, download Github Desktop for a convenient graphical user interface (GUI) to use. (If you're an advanced user/know how to work the command line, you can opt out of using the desktop version.)

After setting up your github desktop, you should land on a page that looks something like this!

first page

Creating A New Github Repo

Step 1

Click on "Create a New Repository on your Hard Drive" then navigate to the folder where you want the git repo to track. For example, I want it to track the folder in my Documents folder called valiDate.

create repo

If you want, you can select a language to initialize the Git Ignore with. This will tell git that there are files you don't care about tracking and don't want committed. For a lot of languages, this means some binary/compiled files that are created when a program runs which are mainly machine interpretable but don't have any meaning to a human. They get generated every time the program runs so you don't have to worry that the program won't work without them.

Step 2: Add files to this folder

Add files as you might typically do to this folder! For example, I want github to track my changes to a renpy game. I created a game in renpy and then cheated a little and dragged the starter files from the renpy game into my github folder like so.

folders

You might have to relocate the original repo folder, but once it's tracking the folder with the game, the ui should look something like:

game

Optional: .gitignore

If you want a cleaner repository, you can take advantage of the .gitignore file! If you navigate to the History tab, the first commit has a file called .gitignore. If you right click on it, you can open the file up in your choice of text editor to edit the file. The default for python looks like this!

python gitignore

Since I'm using renpy, there are a lot of renpy compiled files that the default python gitignore doesn't catch. You can typically tell which files these will be if you click on them in your editor and get a lot of garbage. For example:

python compiled

All of these files end in .rpyc, so we can add the following line to our .gitignore file:

.*.rpyc

* tells git that it should match any file name that starts with whatever but then ends with .rpyc

When you save .gitignore with this change, and switch to Github Desktop, you should see less files in the changed files column and a yellow dot for the .gitignore file. I'm going to leave out the files that end with .rpyb and .rpymb as well.

gitingored

Another way of adding specific files is to right click on one of the files and add it to the gitignore manually!

manual git ignore

Step 3: Committing Code!

Once your commit looks good and you're ready to save this version to your repository. Add a summary and press the commit to master button!

Step 4: Publish Repo

Publish the repo for it to show up online in your github.com account! You only need to do this once.

Contributing To An Existing Repo

If you're contributing to a project that someone else has started then you might need to clone a repository to bring it into your own local computer to collaborate on!

Step 1

Click on Current Repository > Add > Clone Repository > URL

clone repo

Navigate to the repository that you want clone on a web browser, find the Clone or download button, copy the URL there, and paste it in the URL section in the above image^^^^

copy url

The repo should appear in the list of current repositories!

repos

New Changes to A Repo

Git is really powerful, but as a result, can be a little complicated especially if you work with multiple contributors. From my experience in working in github where I was the only contributor and with only a few other people, the easiest way to keep a clean commit history especially is to never make new branches and only ever commit to master.

This is kind of how a general workflow will look like:

Step 1: Fetch Origin

Step 2: Pull Commit

If you don't have any local changes, then the UI should look like:

pull commit

Step 3: Commit Master

If there are changes on your local machine, then the UI will tell you to commit your code first.

Step 4: Resolve Merge Conflicts

If there are changes in origin that conflict with your local changes (for example two people trying to change the same line) then you might get a merge conflict.

merge conflict

Open the file in the editor of your choice (mine is Atom) ctrl+f for <<<<<<< or ======= or >>>>>>>.

merge conflict file

Change the file to get rid of all of those markers.

merge conflict file 2

Once all of the conflicts are resolved, the UI should look like this:

no more conflicts

And you should be able to push to origin as usual!

push origin

Conclusion

And that's the basic gist of using Github! Go forth and share that code!!!!