This tutorial will focus on using github through the github desktop app using a renpy game as an example.
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!
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
.
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.
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.
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:
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!
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:
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.
Another way of adding specific files is to right click on one of the files and add it to the gitignore manually!
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!
Publish the repo for it to show up online in your github.com account! You only need to do this once.
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!
Click on Current Repository
> Add
> Clone Repository
> URL
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^^^^
The repo should appear in the list of current repositories!
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:
This will bring changes that other people might have made into your local copy.
If you don't have any local changes, then the UI should look like:
If there are changes on your local machine, then the UI will tell you to commit your code first.
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.
Open the file in the editor of your choice (mine is Atom) ctrl+f for <<<<<<<
or =======
or >>>>>>>
.
Change the file to get rid of all of those markers.
Once all of the conflicts are resolved, the UI should look like this:
And you should be able to push to origin as usual!
And that's the basic gist of using Github! Go forth and share that code!!!!