Creating Your First Source Control Repository
By the end of this lesson, you will have a local Git repo connected to a remote Git server, with a Unity project in it.
If you already have a repository with source control (Git, Subversion, Perforce, or Mercurial) for your project, or want to use a sample project to test out Unity Cloud Build, you can proceed to Lesson 3: Creating Your First Cloud Build Project.
In this lesson, you will create a repository using the following
- Bitbucket: A free repository for small projects
- Git: A popular source control system, integrated with Bitbucket.
- SourceTree: A user-friendly GUI that works with Git and Bitbucket.
These tools are good for SCM beginners because they enable fast setup and easy use.
To get started, you’ll need an existing Unity project on your local machine. If you do not have one, complete the following tutorial: Space Shooter Tutorial
1. Download SourceTree
Go to www.sourcetreeapp.com to download and install SourceTree.
2. Create a Bitbucket Account
Visit bitbucket.org and sign up for a free Personal Account.
When asked to create your first repository, ‘No thanks’. We will be creating a repository with SourceTree.
3. Using SourceTree, create a repository on Bitbucket.
Open SourceTree and enter your Bitbucket login username and password when prompted.
After logging in you will be prompted to “Clone” your repo (to “Clone a repo” is to copy all the relevant files from a repository to your local machine). If you have not created a repo associated with your Bitbucket account, the list should be empty. Click “Skip Setup”.
After clicking “Skip Setup”, you will see the Repository Browser window.
We will create a remote repository using the Bitbucket account you previously created. Click “+ New Repository” in the Repository Browser. You will see a dropdown list. Choose 'Create a remote repository'.
You will be prompted with a “Create a remote repository” window.
Use the following configuration settings:
- Account: Bitbucket Account
- Owner: Bitbucker User name
- Name: Any
- Description: Any
- Type: Git
- This is a private repository: Checked
You will be brought back to the “Repository Window”. Click on “Remote” and you should see the name of the repo you just made in the list.
4. Clone Your Repo
From the Repository Window | Remote window, click on the Bitbucket repository you created in the previous steps. The following prompt will appear.
- Source URL: Leave as-is, but take note of it, as you will use it later when configuring Unity Cloud Build
- Destination Path: Choose a location on your local machine where repository files will be stored. Note that the Destination Path must point to a directory that has no items in it.
- Name: Any
- Advance Options: Leave as-is
After, you will be brought back to the Repository Window | Local, where you will see the local copy of the repository you just created. Note that the repository is empty; you will populate it in the next steps.
5. Populate your local repo with your Unity Project
From the Repository Window | Local, double click on your repo. Enter your name and email when prompted.
You will now populate your local repository. Find your Local Unity Project and move all files to the repo Destination Path you defined in Step 4. In the following screen shot, the unity project “MyFirstProject” will be moved into the local repository folder “MyFirstUnityRepo”
Upon populating your local repo, SourceTree will automatically detect changes and will update, as follows:
6. Commit and Push your Local Repo to the Remote Repo
Unity Cloud Build monitors your remote repo. To do so, you must COMMIT and PUSH your files to the remote repo.
Select the “Unstaged files” check box to select all files that will be pushed to the server.
NOTE: You'll notice three dots (•••) to the right of each filename - click these dots to access a 'more' menu. Use this menu to select 'Ignore file' for your Unity ‘Library’ folder (Unity Cloud Build will construct the Library folder during the build process). You can also 'Ignore' any other files that aren't required by Unity to build your project. Not completing this step will make the build process slower that necessary.
Click “Commit” on the top of the screen. Enter your name and email if prompted.
Enter in comments and click “Commit”
The following should appear: "There is nothing left to commit"
Click “Push” to copy all committed files to the Remote Repository.
Click “OK”. This will initiate the upload process.
7. Check your remote repo
Go to bitbucket.org and login with your credentials. You should see your repository name listed on the first screen. Click it's name to go to the page about your repo.
Once you're on the repo page, go to the address bar in your browser and copy the url / address you see there.
This will be the URL that you give Unity Cloud Build when you add a new project. Click the 'Git' tab on this page, or follow the instructions in the Unity Cloud Build setup wizard to add an SSH key to your Bitbucket account to allow access.