Unity - Let’s GIT started!
One important aspect of software development is version control. An aspect I did not really care about at first.
…Until my hard drive had a failure and I lost basically everything…
To avoid that pain, you can use Git in combination with GitHub for version control. Even if you encounter an hardware failure, your months-old project still works as it should and is not lost in the data graveyard.
Git is a command-line utility which helps you to get your project uploaded and saved on a remote server, in this case, GitHub.
The very first step is to download Git for your OS. Click the link and it should take you to the download site. As I am on Windows, I see “Windows” build at the bottom right. Start the download and run the installer.
Click “Next” until the installation has finished. Either check the “Run Git bash” checkbox or search for “Git” and run the Git Bash.
A window like this should open up.
I’d recommend you to configurate git at first with the following commands:
git config --global user.name “<yourUsername>”
git config --global user.email “<yourGitHubMail>”
These commands are telling the remote server who you are and will be used for authentication. You’re setting your name which your team will see if you work with other teammates.
Setting up the repository
Now that we have set up Git, we can now create the repo on GitHub.
The GIF shows you how:
- Give your repo a name
- Give your repo a description if desired
- Set the visibility to public or private
- Add a .gitignore file for Unity
Set up the local repo
In order to make git work and sync your project with the remote server, you need to create a local repository.
- Open up the Unity Hub
- Right-click the project > “Open in Explorer”
- Right click the explorer > “Open Git Bash here”
- Type in “git init” to initialize the local repo
Connect the remote server
Now we have to connect the remote server in order to properly synchronize our local files with the cloud server.
- Open up GitHub
- Click on your desired repository
- Click on the green “Code” button
- Copy the HTTPS URL
- Go back to git and type in “git remote add origin <CopiedURL>”
Using origin is an industry standard which simply means “The origin of our repository”.
In order to verify the connection, type “git remote -v” into git. If you see something like this, then everything has worked and the remote server was successfully added.
And there we go! We successfully created a new repository and set up a connection with our local project. Now we are ready to create some things i Unity and use Git for storing our progress in the cloud! But how do we actually upload and update our project on the GitHub repository? Read more about that in the next article coming pretty soon!
Thank you for reading. I hope you can now set up Git without the need of another tutorial now! Have fun creating! :)