Most people don’t know how to ask a question effectively, don’t be one of them. An important part of learning is figuring out how to ask for help, and how to do it properly.
If you’re serious about game development, you’ll save yourself a lot of time and headaches by learning about a source control.
In this lesson we’ll learn to make a git repo with github, commit changes, and push those changes to a remote server. It’s time to GIT GUD! (get it? Yeah ok, I’ll stop)
What is source control?
Source control is a way to backup and organize your code so that if anything happens to
your computer you’ll always have a backup copy and won’t lose hours, or worse… months… of
work. Sure you don’t need to use source control to make games, but I highly suggest you do
and I strongly encourage anyone interested in game dev to make it a regular part of your
In this tutorial, we'll be using git to store and backup our files. If you don't want use git, at the very least use a service like dropbox to back up your files. However, be warned that in a game development studio you'll probably be required to use some sort of source control, so it's a good idea to learn how to use it properly. In this first tutorial, we'll be using the github desktop client, but in the future we'll also learn to use git with your computer's command line.
Before we can start our lesson you'll need to open an account with a company that allows you to create a git depot. Both github and bitbucket allow you to have free git repos. On github these repos will be public (everyone can see your code) while bitbucket allows you to make public and private repos. For this lesson, we'll focus on github, but most of the things that we'll do in this tutorial should be transferable so choose the option that works for you.Sign up for a free github account here or Sign up for a free bitbucket account here.
Making a repository
Once you have an account, make a new repository (repo) by logging into your github account and clicking on the "+" menu. We'll use this repo to play a version of the game Exquisite Corpse in another post, so select "new repository" and name your repository "ExquisiteCorpse". Finally, click "Initialize this repository with a README".
Setting up the desktop client
Now that you created your new repo, it's time to add something to it. We'll be creating
and adding the files "story.txt" and "nextLine.text." To do this first
download the github desktop client.
Once you finish downloading the desktop client, sign in, and configure the client. During
this process, you should see the following screens:
Cloning the repo
Next we need to get the repo you made on the git hub website onto your computer. We'll do
this by cloning your repo.
With the git desktop client open got to File->Clone Repository. You should then see a pop up window asking you for the repo Url or github username and repository. You'll also be asked for your your Local Path. For the repo Url, go back to your github repo page and click on the Clone or download button and copy the Url.
Adding files and committing changes
When you open README.md for the first time there should only be one line of text "# ExquisiteCorpse".
Let's add a line to the file that describes this repo. Something along the lines of "This
is a version of Exquisite Corpse to learn how to use git."
Next, let's add some files to the repository. Using your plain-text editor, make two new files called "story.text" and "nextLine.txt" and put them in the same folder as your "README.md" file.
Finally, go back to the github desktop app. it should look like the following screenshot.
First, you'll notice that all of your files are listed on the left side of the app under changes. The colors next to the file names tell you a few things about those files. Green shows that new file that has been added to the repo, Yellow shows that a file has been modified, and Red (which we don't see right now) would indicate that the file has been removed.
On the right, the git desktop app will show you what changes have been made to your files with line numbers indicating where the changes took place. This section of the app follows the same Green, Yellow, Red color scheme as the file tab.
Now that we've added files, let's commit them. Fill out the summary field with a message that accurately reflects the changed you made. In this case, the message can simply be "Added initial files" or initial commit. However, as the project evolves you'll want to make this message more descriptive, especially if you're working with others. Once you're done click on the "Commit to master" button. Congratulations! You just made your first commit! Now... what does that mean? Well, it means that your computer is now keeping track of the changes you make to your files. In order to fully understand what that means let's do something drastic. Let's delete one of the files we created.
Go back to the folder with the files we created. Select the README.md file and delete it. Next, open your github desktop app and you should see something like this:
Pushing your files to github
Now that you're tracking your changes locally (on your computer) we'll talk about another powerful feature of source control: backing up your files on a remote server. Go back to the github app and click on the button that says Push Origin. Clicking this button publishes all of the changes to your github account. To see what this means, go back to github.com, log in, and navigate to your ExquisiteCorpse repo. You should now see your files on your account.
Congratulations! You have now created a repo, learned to tracked changes locally, and published those changes to your github account! Supercharge your gamedev with part 2 of our github tutorial!
Till next time, game on!