As a game developer, you’re likely familiar with the power of Git and GitHub. These tools are essential for managing and tracking changes to your codebase, especially when working in a team. But are you using them to their full potential? In this article, we’ll explore ten best practices for using Git and GitHub, specifically tailored for game developers using GameMaker Studio 2.
1. Keep Your Code Short and Sweet
The first rule of thumb is to keep your code as clean and concise as possible. This not only makes your code more readable but also easier to maintain. When your code is easy to read, it’s easier to maintain. And when it’s easier to maintain, it’s more likely that people will want to collaborate with you on your projects.
2. Make Incremental, Small Changes
When working on a game, it’s tempting to make large, sweeping changes to your code. However, it’s best to make small, incremental changes instead. This makes it easier to test your changes and roll them back if something goes wrong. Plus, small commits decrease the likelihood of integration conflicts, especially when those changes have been properly documented in the form of descriptive commit messages.
3. Keep Commits Atomic
An atomic commit is a single unit of work, involving only one task or one fix. Atomic commits make code reviews faster and reverts easier, since they can be applied or reverted without any unintended side effects. The goal of atomic commits isn’t to create hundreds of commits but to group commits by context.
4. Develop Using Branches
Using branches, you can make changes without affecting the main codebase. The running history of changes are tracked in a branch, and when the code is ready, it’s merged into the main branch. This ensures that bugs and vulnerabilities don’t work their way into the source code and impact users.
5. Write Descriptive Commit Messages
Descriptive commit messages are as important as a change itself. Write descriptive commit messages starting with a verb in present tense in imperative mood to indicate the purpose of each commit in a clear and concise manner. Each commit should only have a single purpose explained in detail in the commit message.
6. Obtain Feedback Through Code Reviews
Requesting feedback from others is an excellent way to ensure code quality. Code reviews are an effective method to identify whether a proposal solves a problem in the most effective way possible. This is especially important for junior developers, because through code review, senior developers can transfer knowledge in a very practical, hands on manner.
7. Identify a Branching Strategy
Determining a single branching strategy is the solution to a chaotic development experience. While there are several approaches to development, the most common are centralized workflow, feature branching, GitFlow, and personal branching. Regardless of the strategy, it’s important to communicate the decision and workflow logistics to team members and provide training if the approach is new to some members.
8. Use .gitignore
A .gitignore file specifies intentionally untracked files that Git should ignore. This is especially useful for files that are generated during the build process, such as .o and .class files, log files, or files produced by your continuous integration system.
9. Secure Your Account with Two-Factor Authentication
Two-factor authentication (2FA) is an extra layer of security used to ensure that people trying to gain access to an online account are who they say they are. It’s a good practice to enable 2FA on your GitHub account to prevent unauthorized access.
10. Use SSH keys instead of HTTPS
SSH keys provide a more secure way of logging into a server with SSH than using a password alone. While a password can eventually be cracked with a brute force attack, SSH keys are nearly impossible to decipher by brute force alone.
By following these best practices, you can streamline your game development process and ensure that your codebase remains clean, organized, and easy to navigate. Happy coding!