Setting Up Git with Unity

Connecting Git with Unity

The first step to using Git with Unity would be to download Git Bash. Git Bash is a command-line interface which allows you to communicate with web sites such as GitHub. It will be your “middle-man” between GitHub and Unity.

Installing Git Bash:

  • Click on the following link or type the URL into your browser.
    https://git-scm.com/downloads
  • Click on the option for your OS and click the download button.
GitHub Download Page
  • After the download has completed, open the downloaded file and click through the default installation setup.
GitBash Installation
  • Once Git Bash is installed, you can access it from your START Menu or PROGRAMS/APPS Folder.

An Added Bonus

Git — help Command

Navigating Git Bash

Here are some simple tips to help you navigate Git Bash.

First, you will search for your Unity Projects Folder on your PC/Mac.

  • Check to see if the folder you are searching for is accessible from the current screen by typing the following command:

ls This is the LIST command. It will list all folders and files within the current directory.

  • NOTE: Commands are shortened to make navigation simpler and quicker.
    Example: ls = LIST
  • Now you know your folder is accessible from within the current directory.
  • You can now access your folder with the following command:

cd This is the CHANGE DIRECTORY command. This command allows you to navigate back and forth between folders.

  • NOTE: Git Bash does not recognize spaces in file and folder names. Capitalization does not matter. You can easily access a folder with the following methods:

By typing cd followed by 2 or more letters of the folder name, then pressing Tab on your keyboard. This will autocomplete the folder name.

OR

By typing cd followed by folder name inside quotations.

cd (Change Directory) Command #2
  • Upon reaching your desired projects folder, ensure you access the correct folder of the project you wish to connect to GitHub. Type ls to return a list of projects, then use cd to access the folder using one of the previously mentioned methods.
Accessing Correct Project
  • An alternate way to access the folder directly without commands, is to right click inside your project folder and select Git Bash Here. This will open Git Bash at the location of the respective folder.
Using Context Menu to Open Git Bash

Connecting GitHub to Your Unity Project

  • Choose your desired GitHub repository. Click the Code button to open a menu box. Click on the “clipboard” icon to copy the HTTPS URL.
Copy GitHub URL Code
  • Use your desired method to access your Unity Project folder with Git Bash (command line or right click context menu).
  • Use the git init command in Git Bash to initialize a new repository. If the repository has already been initialized, as mine has, it will show “Reinitialized”.

NOTE: Git repository commands must always begin withgit”.

Initialize Git Repository
  • Use git remote add origin (paste HTTPS URL Code from earlier).
git remote indicates the repository type being created
add instructs Git Bash to add a NEW repository
origin is the standard name given to a GitHub remote repository
HTTPS is the copied Code URL you obtained from GitHub
  • Note: If it already exists, as mine does, you will receive the following message:
    error: remote origin already exists.
Remote Add Origin
  • Use the git remote -v command to verify a successfully added repository
Git Remote Verify
Fetch: indicates the ability to retrieve (fetch) information from the GitHub repository
Push: indicates the ability to send (push) content from PC/Mac to the GitHub repository

Git Documentation

For the latest up to date documentation on Git, check out the complete library of fully explained Git commands, including tutorials and videos.
https://git-scm.com/doc

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
James Hills

James Hills

I am a married father of 5 children. I decided at 13 years of age that I was going to become a Software Developer.