Last time, new Unity project was started, as well as an initial commit, and a few extra ones. Now to add a remote repository!
Remotes are great for a number of reasons. If you’re working with other people, you can add their repository as a remote, and pull in the changes that they made to their project into your own project. It’s more common, however, to have one remote repository, and have members push & pull from that repo to share work. There are a few caveats that people need to be aware of (trying to fix merge conflits), but it’s generally painless, unless you and your coworker(s) are completely out of synch.
So, now to set up a simple remote repository. We’ll want to do this somewhere, well, remote, and not on the local machine. Redundancy is useful, especially if a local machine decides to crash, and you have another machine that you can work on. Also, the aforementioned working as a team; quickly pulling in changes is nice. What I’m going to do, is set up my remote repository within Redmine directory, for reasons I will explain later. Currently, I use Lindoe, and it’s been great to me so far. So, let’s say I’m in my online Redmine folder, and want to create a new remote repo:
[shawn@remote ~]$ cd Redmine/gitRepos/testRemote/ [shawn@remote testRemote]$ mkdir testRemote.git [shawn@remote testRemote]$ cd testRemote.git/ [shawn@remote testRemote.git]$ git init --bare Initialized empty Git repository in /home/shawn/Redmine/gitRepos/testRemote/testRemote.git/[shawn@remote testRemote.git]$ ls -al total 40 drwxrwxr-x 7 shawn shawn 4096 Mar 26 21:20 . drwxrwxr-x 3 shawn shawn 4096 Mar 26 21:20 .. drwxrwxr-x 2 shawn shawn 4096 Mar 26 21:20 branches -rw-rw-r-- 1 shawn shawn 66 Mar 26 21:20 config -rw-rw-r-- 1 shawn shawn 73 Mar 26 21:20 description -rw-rw-r-- 1 shawn shawn 23 Mar 26 21:20 HEAD drwxrwxr-x 2 shawn shawn 4096 Mar 26 21:20 hooks drwxrwxr-x 2 shawn shawn 4096 Mar 26 21:20 info drwxrwxr-x 4 shawn shawn 4096 Mar 26 21:20 objects drwxrwxr-x 4 shawn shawn 4096 Mar 26 21:20 refs [shawn@remote testRemote.git]$
This is the same thing done to set up the local repo, except, it’s bare. Within the local repo, there’s a folder called ‘.git’. When a bare repo is created, you’re basically creating a repo with only the contents of the .git directory. You’ll want to set up a bare repository for your remote repo. I also could have cloned my local repo, but made a bare clone, then copy that to the remote machine.
Now, to tell our local machine about this repository. To do this, you can run ‘git remote –add’, with a few more details after ‘add’. The command is git remote add “remoteName” [URL]:
shawn@SHAWN-PC ~/Desktop/TestProject (master) $ git remote add mainRemote email@example.com:/home/shawn/Redmine/gitRepos/testR emote/testRemote.git shawn@SHAWN-PC ~/Desktop/TestProject (master) $ git remote -v mainRemote firstname.lastname@example.org:/home/shawn/Redmine/gitRepos/testRemote/testRemote.git (fetch) mainRemote email@example.com:/home/shawn/Redmine/gitRepos/testRemote/testRemote.git (push)
The remote name, is what we’re going to call this remote, and the URL is the path to the .git folder. Git remote -v shows the remote repositories that have been set up. We can see that the newly set up remote is on that list. Time to push the local repo to the remote:
shawn@SHAWN-PC ~/Desktop/TestProject (master) $ git push mainRemote master Counting objects: 21, done. Delta compression using up to 4 threads. Compressing objects: 100% (20/20), done. Writing objects: 100% (21/21), 11.30 KiB, done. Total 21 (delta 9), reused 0 (delta 0) To firstname.lastname@example.org:/home/shawn/Redmine/gitRepos/testRemote/testRemote.git * [new branch] master -> master shawn@SHAWN-PC ~/Desktop/TestProject (master) $
(We had to specify the master branch for this first push. Later on, we can just say ‘git push remoteName‘ and be done with a push)
So, now, we have a remote repository which has everything we did locally. Fun times. Now, if someone wanted to, they could clone the remote repo onto their machine using ‘git clone‘. I’m to clone the remote repo on my Desktop:
shawn@SHAWN-PC ~/Desktop/TestProject (master) $ cd .. shawn@SHAWN-PC ~/Desktop $ git clone email@example.com:/home/shawn/Redmine/gitRepos/testRemote/testRemote.git Cloning into testRemote... remote: Counting objects: 21, done. remote: Compressing objects: 100% (20/20), done. remote: Total 21 (delta 9), reused 0 (delta 0)Receiving objects: 61% (13/21) Receiving objects: 71% (15/21) Receiving objects: 100% (21/21), 11.30 KiB, done. Resolving deltas: 100% (9/9), done. shawn@SHAWN-PC ~/Desktop $
I had to specify the URL of the online repo, ending the URL in .git. Let’s take a look at the log for this clone repo:
shawn@SHAWN-PC ~/Desktop $ cd testRemote/ shawn@SHAWN-PC ~/Desktop/testRemote (master) $ git hist * [45bcf31] 2012-03-26 (HEAD, origin/master, origin/HEAD, master) | Another Great Update * [21adf6e] 2012-03-26 | Initial Commit shawn@SHAWN-PC ~/Desktop/testRemote (master) $
It’s the same history for the original repository that was set up! It would make more sense if I cloned this onto a different computer, of course. Also, when you clone a repository, it automatically the source URL as a remote repository called origin.
shawn@SHAWN-PC ~/Desktop/testRemote (master) $ git remote -v origin firstname.lastname@example.org:/home/shawn/Redmine/gitRepos/testRemote/testRemote.git (fetch) origin email@example.com:/home/shawn/Redmine/gitRepos/testRemote/testRemote.git (push)
You can rename this if you would like, using git remote rename [old name] [new name]. You can also make changes here, push to the remote repository, then have other people pull the changes that you pushed. Now, this is being oversimplified, and for a better understanding of some of these features, I strong suggest sources such as Git Immersion and Pro Git.
With Redmine, you’re able to add a repository for a specific project to track. You can do this within the Settings –> Repository section of your project within Redmine. Remember that url for the bare repo I created? Let’s get that, and add it to the page:
(Note: The repo needs to be within the actual Redmine directory on the machine with Redmine. For more info, check out this page). Now, we have a new tab next to Settings called “Repository”. On that page, we’ll see the repository’s details, such as the Assets and Project Settings Folder. Clicking on the folder, or the corresponding “+” icon, will show you the contents of that folder. Now, anytime someone pushes changes to this remote repository, the changes will be reflected on this page.
As others probably know, Unity does come with its own Version Control System, the Asset Server. It is a very nice tool, and definitely useful. I’ve used it during game jams, and the speed of the asset server is wonderful. For something fully integrated into Unity, you’d expect it to be that good. However, there are some things that I do find useful about using other version control systems over the Asset Server (at least, for now).
For example, you can’t really use the Asset Sever in any type of way outside of Unity. As far as I know, there aren’t many project management tools you can use with Unity, which are also integrated (however, this one looks very good). I can, however, easily use Unity and Git and Redmine together, without too much of a drop in the workflow, compared to just using the Asset Server.
For example, within Redmine, I can create a task (called issues in Redmine), something along the lines of “Make Project Great!”. After creating this issue, Redmine will assign it a number. I now have task “Issue #277: Make Project Great”.
So, now to Unity. After ‘x’ hours, I’ve made a bunch of changes to my project, all of them related to issue #277. So, I save my work, and commit this to my local repository. But, let’s make the commit look like this:
shawn@SHAWN-PC ~/Desktop/TestProject (master) $ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: Assets/Example.cs # modified: Assets/ExampleScene.unity # no changes added to commit (use "git add" and/or "git commit -a") shawn@SHAWN-PC ~/Desktop/TestProject (master) $ git add . shawn@SHAWN-PC ~/Desktop/TestProject (master) $ git ci -m "Did really cool things; refs #277" [master 1b2b47e] Did really cool things; refs #277 2 files changed, 4 insertions(+), 6 deletions(-) shawn@SHAWN-PC ~/Desktop/TestProject (master) $
The ‘ref #277’ does what one may assume it does. It references issue #277 in Redmine. Rather, it will, once I push it to the remote repository. So….
shawn@SHAWN-PC ~/Desktop/TestProject (master) $ git push mainRemote Counting objects: 9, done. Delta compression using up to 4 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 1.58 KiB, done. Total 5 (delta 2), reused 0 (delta 0) To firstname.lastname@example.org:/home/shawn/Redmine/gitRepos/testRemote/testRemote.git 45bcf31..1b2b47e master -> master
And after pushing, let’s take a look at our repository page in Redmine again:
The commit message shows up, and the ‘#277’ is linked. If we click on it, we’re brought directly to the issue we created beforehand. And now, we can even see this commit show up on that page:
This can turn out to be very useful for larger projects, or projects which see a good number of updates a day. It’s relatively easy to lose track of a project, and if something goes wrong, there’s a lot of visual feedback to help track down which commit caused the problem, and what part of the project someone was working on when that specific commit caused the problem. Of course, it’s only as good as the people using the tools. If no one keeps track of what they are doing, then it’ll be a bit more difficult to track down bugs and similar negative issues. There are other ways to interact with your issues through commits, such as close issues through commit messages as well — git commit -m “Made game great!; closes #24” , then push your changes to the server — which will close the task, and let everyone know that you’re finished making the game great if they were to look at the task.
Now, of course, there are a number of things that you need to be aware of. While Redmine is free/open source, you do need to set it up on a machine. This means man hours with trying to set it up, and money for a machine to host it. It all depends on what you’re willing to sacrifice!
That’s it for this 2-parter. What I covered is really just the surface. There’s a lot more to be uncovered, and definitely things that could be made better/more optimized/etc. But hopefully someone finds something here useful to some degree.