Setting Up Version Control for Unity
It doesn’t matter whether you are developing games or web applications, always use version control. In the case of Unity, the configuration will be the same, only the .gitignore file will have a different configuration. To get started with a version control system, install Git from https://git-scm.com/ and learn some of the most important commands.
Starting a new project
If you’re starting a new project, it’s important to first initialize version control on your local system and then connect it to a remote directory on Github, Bitbucket, or Gitlab. Follow these steps:
1. Create a new Unity Project on your local machine.
2. Add a repository on Github or another alternative service. Remember to add .gitignore and choose Unity .gitignore template.
3. Open terminal on your local machine and navigate to unity project, initiate git and connect with remote repository.
git init
git remote add origin github_repository_url
git pull origin main
git remote -v
git status
git add .
git commit -m "Created a new Unity project"
git push origin main
Master vs Main
In the recent years since the recording of these videos, the IT community as a whole has decided to move away from certain offensive terminology. To this end GitHub no longer uses ‘Master’ as the default name for the primary branch of a repository. You can use the following command in GitBash to correct the default naming in git.
git config --global init.defaultBranch main
And if your current repository has a the Master branch, you can use the following to fix it.
git branch -m master main
Teamwork
If you work in a team, it is important to follow one rule to avoid merge conflicts, which includes three points:
- Pull
- Commit
- Push
git pull origin main
git add .
git commit -m "feat: feature name"
git push origin main
Team collaboration requires working with branches, so if your task is to create a new feature, you should create first a new branch, switch to that branch, and work on that branch.
: 'Example:'
git branch feat/recharging
git switch -b feat/recharging
: 'Code the recharging feature'
git add .
git commit -m "feat: recharging"
There are some other types of branches like dev, release or hotfix. More about branches types you can read in my next article GIT Branching Strategy.