Managing Multiple Repositories With Git

I’ve started a small side project with a friend of mine. It’s a Ruby on Rails project and he has been doing the design work while I’ll be handling some of the Ruby/Rails backend pieces. For many reasons we went with Git as our source control system, the main reason for this is because we are separated by a few states. Since he has been adding UI elements to our app, I had to figure out how to bring his changes down to my local repository while maintaining the separation I need so his work doesn’t mix with my master or dev branches (at least not yet). The reason I want to not bring his changes into my master or dev branches yet is because it’s not done, but I do want to see and “touch” the UI work he’s doing. I figured I’m not the only person looking to do this so I figured I’d throw up a quick blog post about it.

The first thing you have to do is add the git remote for the other user’s code.

[text]
git remote add my_new_remote git@github.com:mypartner/OurProject.git
[/text]

This adds a git remote, with the name “my_new_remote” and that is pointed at my partner’s fork of our project.

Next you’ll want to fetch the remote repository (as usual, with git this will include the entire change log, and all files).

[text]
git fetch my_new_remote
[/text]

After you have the remote, you can create a new local branch that points at the newly fetched code. Below I create a branch called “partner_dev” and point it at my_new_remote/dev (assuming that there is a branch called dev in my partner’s repository)

[text]
git checkout -b partner_dev my_new_remote/dev
[/text]

Now you can look at the changes made to the repository but keep it separate from your work. This is a nice way to mess around with other people’s work without having to bring it into your own. I’ve been using this method to checkout the UI template changes my partner has been committing every few days.

This entry was posted in programming. Bookmark the permalink.