Version Control - your new best friend. How to use Git

Matej Marek
5 min readMar 24, 2021

How do I install git? - read about it here!

Now that you have Git installed, what’s next? First, you will need to create a GitHub account, which you will use as a platform to store your repository.

In this article, I will show you how to set this up with your Unity project and show you the basics of Version Control - you’ll be ready to use Git on your own in no time.

GitHub - Account and repository creation

GitHub is a free code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere in the world.

To start creating your own repositories, you will first need a GitHub account. You can create it here - do these few easy steps, and you are in!

How to create a repository

After you log in to your GitHub account, you will see a navigation panel. Click on the ‘Repositories’ button. Here you will see the list of all of your (future) repositories. To create a new one, click on the ‘New’ button.

Here you will have multiple options. Apart from the name of your repository, the main thing to set up is to choose whether you wish to keep the repository Public ( anyone can see its contents ) or Private ( only you and people invited to see this repository can see its contents).

One thing you should never forget to set up is .gitignore - There are many files in your project that should be ignored and shouldn’t be uploaded into your repository. In this case - choose the Unity template.

After you are satisfied with your options, click on the ‘Create repository button - and your repository is created! You will be redirected to the repository page.

Version Control Basics

The basic cornerstones of Version Control are four commands: Fetch, Pull, Commit and Push.

  • Fetch: This command download commits, files, and refs from a remote repository into your local repository.
  • Pull: Incorporates changes from a remote repository into the current branch. By default, pull is shorthand for fetch, followed by merge FETCH_HEAD.
  • Commit: Create a new commit that contains new files or changes of existing files you’ve staged, ready to be sent to the repository. Commit is always included with a commit message, describing the commit's purpose.
  • Push: Uploads your local commits to the remote repository.

How to set up Git for your Unity Project

  • Create a new Unity Project - If you never created one, read this article.
  • Once you have created your project, the easiest way is to open up the project's location. Right-click on the project’s folder and choose the ‘Git Bash Here’ choice.

Git Bash window will open. Now you have to initialize git for this project and connect it to your GitHub repository.

  • Type in ‘git init’ command - this will initialize the local repository
  • Type in ‘git remote add origin <GitHub_Repository_Link>’ - this will connect your local repository with the remote GitHub repository.
  • To verify that we linked it correctly, type in ‘git remote -v.’
  • Now your project should be connected. I will now explain the main commands you will be using daily using Git Bash: Pull, Commit, and Push.
  • Pull: ‘git pull origin <Branch_Name>’ - ‘origin’ stands for the online repository (GitHub). You can’t simply do a ‘git pull’ because Git Bash needs you to specify where to locate your project and from which branch to download files.
  • Commit: ‘git commit -m <your_message_here>’ - before you can run this command, you first have to add files to your commit(‘Stage’ them)
  • To check if you have new changes, type in the ‘git status’ command — this will show you all staged(Green) files and which are unstaged(Red).
  • To add unstaged changes, you can add them all with ‘git add .‘ (The ‘.’ will stage every change) — or add specific files with the ‘git add <File_Name>.’
  • After you are done Staging your changes, you can now run the Commit command - always remember to include the commit message.
  • Push: ‘git push origin <Branch_Name>.’ origin’ stands for the online repository (GitHub). You can’t simply do a ‘git push’ because Git Bash needs you to specify where to locate your project and which branch it should upload the Commit(s).

And that’s it! You have set up your first repository using Git.

Now you know all the basics required to start and connect your projects using Version Control and Git. Of course, there is still more to learn!

To learn more about the branches in git, read this article!

For more Git commands, follow this link.

I hope this guide helped you begin your journey using Version Control and GitHub!

But that is it for now, thank you for reading and feel free to follow me for more articles — and as always, good luck and see you next time!

--

--