Source control is the process of tracking changes to your game's assets, allowing easier collaboration and version management. There are many source control tools out there, but one of the most common ones is Git, used by everyone from students (CPSC 210 anyone?) to multi-billion dollar corporations.
(This document mostly focuses on Git and GitHub, as it's the one I'm most familiar with, and is fairly common.)
Important
This guide is for those with little to no experience using Git. For more detailed information, see the next section.
Source control systems like Git help teams collaborate by tracking changes to files, saving snapshots called "commits," and storing them in a repository on GitHub. This allows teams to easily manage different file versions and combine changes from multiple contributors.
Note
This guide uses a repository called ubc-game-dev-team-5 as an example. Whenever you see it, assume it is your team's repository name.
- Create a GitHub Account: Go to GitHub and sign up.
- (Optional) Ask your team to add you to the repository by sharing your GitHub username or email.
- Install GitHub Desktop: Download it here
- Clone Your Repository:
- Open GitHub Desktop and click "Clone repository from the internet."
- Select your repository (e.g., ubc-game-dev-team-5).
- Explore the Github Desktop interface
- Key Features:
- Red Box: Repository selection. Ensure this matches the repository you’re working on.
- Green Box: Branch selection. Switch branches to work on or view different versions without losing changes.
- Blue Box: Sync options.
- Fetch Origin: Check for new changes from others.
- Pull Origin: Download updates from GitHub.
- Push Origin: Upload your commits to GitHub.
- Purple Box: Commit section. Save your changes locally with a short, clear summary (and optionally a detailed description). Commit often to avoid losing progress.
- Workflow Summary:
- Double-check the Red and Green boxes to confirm the correct repository and branch.
- Click Fetch Origin to check for updates. If there are changes, click Pull Origin to download them.
- Make your changes.
- Repeat Steps 1-2, then create a commit in the Purple Box, and click Push Origin to upload your changes.
- Done!
Note
For further information on workflow and branches, go to the next section
- Repository: The location where all the files for our revision history are stored. Think of it as the hard drive of git.
- Branch: A separate version of your repository that allows you to work on specific features, such as characters or UI, without interfering with others' work.
- Commit: A saved snapshot of the files you are working with
- Merge: Joining together two different branches into one allows the independent changes made on each side to be integrated back into a single thing.
- Push request: A request to merge between branches; after the request is made, others can comment on it for things like requesting changes before the merge proceeds
- Pull/Push: You pull to get updates from GitHub and push to update GitHub with your commits.
If you haven't already, first download git from their website.
There's a few other tools that make Git easier to use, such as providing a Graphical User Interface (GUI):
- GitHub Desktop is a free tool that integrates well with GitHub.
- Most IDEs also have extensions or have Git Built-in:
(Or, if GUIs aren't your thing, you could use the Command Line Interface (CLI), but that might be slower if you don't type very quickly and don't have the commands memorized - like me).
Depending on if you're creating your project or if you're working on an existing one, there may already be a Git repository.
Some teams use GitHub to host their code (either publicly or privately), and if the project already has a repository on GitHub, you may not have to create a new one.
Clone the repository to your machine by using Git:
- Most software (e.g. GitHub Desktop/Rider) supports a Get from VCS (short for Version Control System), which would download it locally
- Alternatively, run
git clone <url>
Important
Do NOT use the "Download ZIP" button on GitHub. It would download the code, but Git requires a .git
directory that gets initialized when git clone
or most VCS tools clones the repo, and downloading the ZIP does not include that directory.
If there is no repository, you can create one on GitHub. Once created, you can upload your assets to the repository.
Note
Some tools (e.g. Rider) allows you to create a repository from your code if one isn't present - such a menu option like 'Share Project on GitHub'
After the repository is cloned, we can make changes to our local version, and then update the remote repository. The typical steps are as follows:
- Create a new branch (unless you want to directly modify the main branch on GitHub), e.g.
cool-changes
- Commit your changes locally to your new branch.
- Push your new branch to the repository
- If you don't have push permissions, ask the administrator of the repository to add you as a collaborator.
- If they insist on not doing that, read the forking workflow
- Create a pull request (or PR) on the repository against main/master (on the repository website: Pull Requests > New Pull Request)
- Some teams may require someone else to review your before merging your changes before merging - you can request it here.
- Merge your changes to main/master
- There's two options: Merge (which keeps your commit history) and Squash (which converts all your commits into 1) - either would work, but you may want to ask in case your team insists on a specific convention
- Done!
In some projects, there could be too many collaborators working on a project (and exceeds GitHub's limit), or maintainers do not trust people to arbitrarily make changes to the main branch (e.g. some malicious actor adding a cryptominer into the project). (A lot of open source projects use this workflow.)
In this case, you would have to do something different:
- Create a fork of the repository (there should be a button on the repository page on GitHub to do so)
- Commit and push your changes to your own repository.
- This can be to your main or master branch - it's not modifying their repository, which is the one they're trying to protect.
- Create a pull request on the repository against main/master using your branch
- Wait for the pull request to be merged - there may be a review process
STAT 406 had slides on how to use Git (with the RStudio GUI): https://ubc-stat.github.io/stat-406/schedule/slides/00-version-control.html#/overview