Whether it’s in the office or around the world, at some point, you’ll have to collaborate with others. And with this, it brings a heap of issues to the table, from pushing the work you’ve done to not having the latest updates. This is where version control comes in. Although there are multiple applications that offers version control, from SVN to Bitbucket, the one I decided to use is GitHub.
When using GitHub, always remember the three steps: Pull, Commit, and Push
- Pull gives you the the “latest” version of the application/branch you’re working on from the remote repository, thus not having deal with conflicting issues or redo work someone else in the team had already done
- Commit lets you record changes to the repository and gives you a way to set up any updated files/folders that needs to be deposited to the remote repository
- Push sends all the updated files/folders you have committed to the remote repository, permitting those in the team to access and view the work you’ve done.
When you first start out on GitHub, you’ll have to create a remote repository for your game. Choose a name you want for the new repository, set it to Public or Private, and can tell GitHub to ignore unnecessary files by adding a .gitignore file in the repository
Once you create the remote repository, it’s time to link it to your project. After copying the repository URL link from GIthub, boot up Git Bash, and change the current directory to the project you want to use.
Next, you’ll need to initialize the repo:
You have to do once and this command will create a local Git repository. Now, you can link the local repository to the remote repository you just created on GitHub by issuing this command
git remote add <server name> <remote repository URL>Server name is usually "origin"
Remote Repository URL is the URL to your GitHub repository
At this point, you’ve already set up your repositories (both local and remote) and now ready to pull, commit, and push your work!
Should always be the first thing you do before you start working. This ensures your local repository is current
git pull <server name> <branch name>Server name is usually "origin"
Branch name is the branch you're currently on. Many times, it'll be "main" or "master" but if working in specific teams, it could be "design", "art", "logic", etc.
Before you can commit, you should always check the status of the repo as this will help you determine if there’s anything that will be added/deleted from the repo once you push your commit.
git statusAnything in Red Text will indicate that file/folder hasn't been added and will need to be added if you want to add it to the push
If you have any files/folders you want to add to the repository, you can add them using this command:
git add <file/folder name>
Individually add files/foldersgit add .
Add all items
Lastly, before you commit, it’s always important to add a comment on what the commit was in case you need to revert back.
git commit -m "Enter Message"
Once you commit your work, it’s time to push it to the remote repository.
git push --set-upstream <Server name> <branch name>set-upstream is usually implied, so you can usually ignore this
Although Pull, Commit, and Push is what you’ll use on a day-to-day basis, sometimes, there are other things you just need to do in order to get the project back up and running.
Like a tree, Git repositories can have many branches, and, with this, it allows the multiple teams to work on the project, organize it, and maintain a safeguard over the project.
Basic commands for branches in Git are:
List all the branches in the repositorygit branch <name>
Create a new branchgit switch <name>
git checkout <name>
Switch the branch you're currently on to a different one
However, do note that whenever you pull from a different branch, anything that’s not part of the branch you want to switch to will disappear.
If, on the other hand, you’re done with the current branch and want to merge it with another branch, type this command
git merge <name>Use the name of the branch you want to merge with the current branch you're on. For instance, if you want to merge the branch "debug" with the "master" branch, you would want to switch to the "master" branch, then merge the "debug" by typinggit merge debug
Although it’s always better to create a new branch to test out things, sometimes it’s better to revert or reset the project to an earlier time.
In addition, even though both revert and reset achieve similar things, it’s important to note the difference:
Revert essentially "undo" an earlier commit by creating a new commit.Reset essentially jumps you back to an earlier point, likely deleting any commit done after that point.
If you’ve decided that it’s better to revert/reset, proceed with caution and type the following commands
Shows you the commits done. Also gives you the hashcode needed in the futuregit checkout <hashcode>
Gives you a chance to see if this is the log you want to revert back to. If not, just switch to another branchgit checkout -b <name> <hashcode>
If this is the point you want to revert it back to, you can create a branch with this point by typing in "-b", a name, and the hashcodegit reset --hard <hashcode>
Reset it to a previous versiongit push --force <server name> <branch name>
Force push a reversion to the remote repository and essentially removing anything after this point.