Setting Up Git with Unity
A Fast and Simple Guide
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.
- Click on the option for your OS and click the download button.
- After the download has completed, open the downloaded file and click through the default installation setup.
- Once Git Bash is installed, you can access it from your START Menu or PROGRAMS/APPS Folder.
An Added Bonus
- To make your transition into Git Bash a bit more comfortable, download the official Cheat Sheet by Atlassian:
- Another method of accessing help with Git Bash commands is accomplished by using the --help command in Git Bash.
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.
By typing cd followed by folder name inside quotations.
- 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.
- 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.
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.
- 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 with “git”.
- 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.
- Use the git remote -v command to verify a successfully added repository
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
For the latest up to date documentation on Git, check out the complete library of fully explained Git commands, including tutorials and videos.