Thanks for stopping by Scott!
update: I’d recommend that you also check out another episode of Hanselminutes when he sat down to speak with David Heinemeier Hansson and Martin Fowler.
As we’re migrating away from Subversion to Git, I’m having to learn a lot about
git-svn. Andy has posted a few articles on this topic, but I wanted to share a quick tip that I find myself forgetting.
Working with Subversion branches
While you’re hopefully already familiar with how great local branches are with Git, you might not know that you can connect local branches to remote branches in your Subversion repository. This allows those of us who are using Git locally to work against Subversion branches.
I’m going to assume the following:
- Your team is using Subversion
- Your team already has a branch that you’re working in
- Your team is following Subversion directory conventions (
- You have Git installed (with SVN extensions)
Checkout the Subversion project with Git
Please visit Andy’s tutorial, Git SVN Workflow, for a more detailed explanation of the following commands.
First, we’ll initialize your new local Git repository with
git svn init -s http://svn.yourdomain.com/repos/project_name
Now, you’ll change directories to your new Git repository.
Let’s fetch all previous revisions into your local repository1.
git svn fetch
Great, once this is done… you’re master (local) branch is linked to
Mapping a local repository to a remote branch
Assuming that your team is working in a Subversion branch on the current iteration of work. Our team has a naming convention for branches for each iteration. For example, if we’re in Iteration 18, we’ll write this as ITER-018 everywhere (Basecamp, Lighthouse, Subversion, etc…). At the start of each iteration, we create a new branch with this naming convention.
ITER-018, the Subversion branch would be located at:
If you were to do a
git branch -r, you should see
ITER-018 show up in the list. Now, the one thing that wasn’t clear when I first read the
git-svn documentation was that you can’t just checkout that branch with one command. In fact, this has tripped me up a few times.
First, you’ll need to checkout a new local branch. I’ve opted to come up with my own convention for local branches and in this case, I’ll name it
git co -b iter_018
So, now I’m in the iter_018 branch, which is local. I’m currently still mapped to
trunk/, which isn’t what we want. However, all we need to do is reset where Git is currently pointed to. We can run git reset to point this to the ITER-018 branch.
git reset --hard ITER-018
That’s it! Now, the local
iter_018 branch will point to
branches/ITER-018 in your Subversion repository. This will allow you to work with your existing repository branch and still reap the benefits of local Git repositories.
What about master?
Good question. The
git reset command that you ran will ONLY apply that that individual local branch. So, master is still pointing to
trunk/. This will allow you to have several local branches that map to remote branches.
If you’re working with Git already.. great!
If you’re working in an environment that using Subversion,
git svn provides you the ability to start exploring Git without making your entire team switchover. Perhaps your a consultant and working for a client that uses Subversion… no problem!
We’re still using Subversion for past client projects and are considering GitHub, which just launched (to the public) today for future projects. A few of us are already using GitHub for open source projects.
Fun.. I just saw the following tweet pass by as I began to wrap up this post.
The Gateway Drug… Git reminds me of Cake
I know that I glossed over a few things, so feel free to post questions and/or tips for others who are looking to dabble with Git.
1 You’ll likely have problems if you don’t have a Git authors file specified in your git config.
...well, creating a fork on GitHub. ;-)
It appears that Rails is moving from Subversion to Git!
Courtenay posted this a little while ago.
git clone git://github.com/rails/rails.git
Check it out the Ruby on Rails project on GitHub.
Start working on your next patch with git…
git clone git://github.com/rails/rails.git cd rails git br -a git br my_patch git co my_patch
This is cool news. :-)
Our team has been migrating towards using Git as our primary SCM. We have way too many Subversion-based projects and repositories to just do a clean switch over and not everybody on the team has had time to start playing with it. Baby-steps…
So, for those of us who want to use it day-to-day, we’re using git-svn.
Also, if you’re on OSX and using Git… check out Justin Palmer’s new project, GitNub, which describes itself as, “a Gitk-like application written in RubyCocoa that looks like it belongs on a Mac.” This looks promising. :-)
It’s currently a whopping 92 LOC with a 1:2.5 code to spec ratio. (I had a goal to keep is below 100 LOC)
- RubyURL on GitHub: http://github.com/robbyrussell/rubyurl
- Public Clone URL: git://github.com/robbyrussell/rubyurl.git
Feel free to grab it and help contribute. This has served almost 14 million redirects since August 2007 and is running on a Rails Boxcar.
To grab it with git.. run:
git clone git://github.com/robbyrussell/rubyurl.git.
Feel free to submit tickets to the Rubyurl ticket system.
UPDATE Ryan McGeary was kind enough to be the first person to help track down a bug and submit patches. :-)
It’s been just over a year since I posted the article, Install Ruby, Rails, and PostgreSQL on OSX and it still gets quite a bit of traffic. Unfortunately, there have been a few changes in the install process that have caught people.
Today, I am leaving my PowerBook G4. It’s being replaced with a MacBook because the logic board is on the fritz. So, guess what that means? I get to install Ruby, Ruby on Rails, PostgreSQL on OS X again! I figured that I would post a revised version of my previous article for those who may go through this same process in the near future.
Step Zero: Install iTerm (optional)
You’ll spend a lot of time in your terminal as a Rails developer. I’m not a big fan of Terminal.app as it lacks tabbed windows1 and you’ll often find me with around ten tabs open. I’ve been using iTerm for a few years and it’s definitely improved in the past year and doesn’t seem to crash nearly as often as it used to.
Once installed, I always change the default color scheme as I prefer the white on black schema. The menus in iTerm are lacking some thoughtful interaction design, but I’ve figured out the right way to do it (after a long time of stumbling on it by accident). In iTerm, you’ll want to edit the Default bookmark, which you can access by going to Manage Bookmarks under the Bookmarks Menu.
Set the Display value to classic iTerm and you’re golden.
Now… let’s get to business…
Step 1: Install Xcode Tools
Without installing Xcode tools from Apple, we’re not going to get very far. First, you’ll need to grab a copy of Xcode, which you can download on Apple’s Developer Connection site. It’s almost a 1GB download, so you’ll want to start your download and use your multi-tasking skills and grab a Viso, read some blog posts.
- Download Xcode (dmg)
I’m going to make the assumption here that you know how to install a dmg on osx. Once this is installed, you can move on to the next step!
Step 2: All Your MacPorts are Belong to Us
MacPorts (formerly known as DarwinPorts) is a package management system for OS X. This is what we’ll use to install most of the necessary programs to develop and run your Ruby on Rails applications. If you’re from the Linux or BSD world, you are likely familiar with similar tools… such as:
You’ll want to download MacPorts and install the dmg file.
Now that this is installed, we should test it.
With a new terminal, run the following:
$ port version Version: 1.442
Success! Let’s get going…
Step 3: Installing the Ruby on Rails development stack
We’re going to go through a series of small steps, which may take some time depending on how fast your internet connection and computer is.
Install Ruby and RubyGems
In order to install Ruby, we’re going to use MacPorts with the
port command, which is now available for installing various packages on our OS X machines.
$ sudo port install ruby rb-rubygems
It’ll probably take a while to download and install Ruby and all of it’s known dependencies. In the meantime, check out some funny code. KTHXBYE!
Still waiting for it to install, perhaps you could do something like… begin writing a comment on this post, writing your own blog post, watch a funny video, or recommend me. I walked to Backspace with Gary to get an Americano… and it’s still not done. :-p
Okay… I trust that it finished installing Ruby and RubyGems without any hiccups. Let’s test them from our terminal to make sure.
Let’s check the version…
$ ruby -v ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]
Now, let’s make sure that Ruby is working properly…
$ irb irb(main):001:0> x = 1 => 1 irb(main):002:0> puts "wee!!!" if x == 1 wee!!!
Great, we’re on a roll. Let’s get the rest of the stack installed.
Install Ruby on Rails
We’re going to install Ruby on Rails with the
gem command that installing RubyGems provided.
$ sudo gem install -y rails
This command should produce an output similar to the following.
Successfully installed rails-1.2.3 Successfully installed rake-0.7.3 Successfully installed activesupport-1.4.2 Successfully installed activerecord-1.15.3 Successfully installed actionpack-1.13.3 Successfully installed actionmailer-1.3.3 Successfully installed actionwebservice-1.2.3 Installing ri documentation for rake-0.7.3... Installing ri documentation for activesupport-1.4.2... Installing ri documentation for activerecord-1.15.3... Installing ri documentation for actionpack-1.13.3... Installing ri documentation for actionmailer-1.3.3... Installing ri documentation for actionwebservice-1.2.3... Installing RDoc documentation for rake-0.7.3... Installing RDoc documentation for activesupport-1.4.2... Installing RDoc documentation for activerecord-1.15.3... Installing RDoc documentation for actionpack-1.13.3... Installing RDoc documentation for actionmailer-1.3.3... Installing RDoc documentation for actionwebservice-1.2.3...
Install Rails-friendly gems
If you’re developing with Rails, it’s highly recommended that you use install and use Mongrel for your development and production environments. The following command will install the mongrel and mongrel_cluster gems (including their dependencies).
$ sudo gem install -y mongrel mongrel_cluster
* Note: Be sure to select the proper platform for mongrel. (hint: OS X is NOT mswin32)
My terminal output:
$ sudo gem install -y mongrel mongrel_cluster Password: Bulk updating Gem source index for: http://gems.rubyforge.org Select which gem to install for your platform (i686-darwin8.9.1) 1. mongrel 1.0.1 (mswin32) 2. mongrel 1.0.1 (ruby) 3. mongrel 1.0 (mswin32) 4. mongrel 1.0 (ruby) 5. Skip this gem 6. Cancel installation > 2 Select which gem to install for your platform (i686-darwin8.9.1) 1. fastthread 1.0 (ruby) 2. fastthread 1.0 (mswin32) 3. fastthread 0.6.4.1 (mswin32) 4. fastthread 0.6.4.1 (ruby) 5. Skip this gem 6. Cancel installation > 1 Building native extensions. This could take a while... Building native extensions. This could take a while... Successfully installed mongrel-1.0.1 Successfully installed daemons-1.0.6 Successfully installed fastthread-1.0 Successfully installed gem_plugin-0.2.2 Successfully installed cgi_multipart_eof_fix-2.1 Installing ri documentation for mongrel-1.0.1... Installing ri documentation for daemons-1.0.6... Installing ri documentation for gem_plugin-0.2.2... Installing ri documentation for cgi_multipart_eof_fix-2.1... Installing RDoc documentation for mongrel-1.0.1... Installing RDoc documentation for daemons-1.0.6... Installing RDoc documentation for gem_plugin-0.2.2... Installing RDoc documentation for cgi_multipart_eof_fix-2.1... Successfully installed mongrel_cluster-0.2.1
Step 4: Installing the World’s Most Advanced Database Server… PostgreSQL!
At PLANET ARGON, we develop our applications on top of PostgreSQL. I’ve long been advocating the adoption of this awesome open source database in the Rails community. Just over a year ago, Jeremy Voorhis (PLANET ARGON alumnus) and I were interviewed on the Ruby on Rails podcast and had the opportunity to discuss our preference of PostgreSQL over the alternatives (mysql, sqlite, firebird, etc.).
We’re going to install PostgreSQL 8.2 from MacPorts by running the following command.
$ sudo port install postgresql82 postgresql82-server
While this is installing, you might take a moment to check out some space shuttles.
Setting up PostgreSQL
You may have noticed the output of the previous port installation of PostgreSQL 8.2, suggested that you do the following. Let’s do that now…
$ sudo mkdir -p /opt/local/var/db/postgresql82/defaultdb $ sudo chown postgres:postgres /opt/local/var/db/postgresql82/defaultdb $ sudo su postgres -c '/opt/local/lib/postgresql82/bin/initdb -D /opt/local/var/db/postgresql82/defaultdb'
Have PostgreSQL start automatically on system start-ups
Unless you’re concerned about extra applications running in the background, I’d encourage you to add PostgreSQL to launchd, which will start it automatically after system reboots.
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql82-server.plist
Adding PostgreSQL commands to your $PATH
For some reason, MacPorts doesn’t add the PostgreSQL programs to the default bash PATH, which means that you can’t run
dropdb without specifying the full path to where they were installed. What we’ll do is add them to our default terminal profile.
(you can use
sudo vi /etc/profile
joeor any other preferred editor to do this)
This file gets loaded every time a new terminal session is started.
/opt/local/lib/postgresql82/bin to the end of the value for PATH.
Save the file and then open a new terminal. To test this, you should get the following output when you run
$ which psql /opt/local/lib/postgresql82/bin/psql
Creating a new PostgreSQL user
When I’m working on Rails applications in my development environment, I really don’t want to have to specify a username and password in every
config/database.yml file for each of our ongoing client projects. When PostgreSQL was installed, it created a superuser named
postgres, which is great, but I’d like one that matches my system username, so that I’m not prompted at all for a username or password to connect to PostgreSQL.
To do this, we’ll use the
createuser command, which comes with PostgreSQL. As you can see, I’m creating a new user with superuser privileges (and will hopefully be the last time I have to do a -U postgres).
$ createuser --superuser robbyrussell -U postgres CREATE ROLE
Let’s take a quick moment to test this out.
# create a new database $ createdb my_test_db CREATE DATABASE # drop the database $ dropdb my_test_db DROP DATABASE
Great, everything looks good here.
We now have a running installation of PostgreSQL with a new user account. All we need to do now is install the appropriate RubyGem to allow our Ruby applications to connect to it.
Installing the Ruby Postgres gem
UPDATE: Hydro posted a commented, which lead me to the ruby-postgres gem.
You can install ruby-postgres gem by running the following command.
$ sudo gem install -y ruby-postgres
Let’s take a moment to test that this installed properly.
$ irb irb(main):001:0> require 'rubygems' => true irb(main):002:0> require 'postgres' => true
If this returns true, than we should be good to go. We’ve now built a professional development environment for working with Ruby on Rails. Doesn’t that feel great?
Test your install
You can look back at my older post to walk through the process of testing out your setup with a new Rails application.
I hope that this post has been useful for you. It took me a few hours to walk through this process and it’s how all of our designers and developers at PLANET ARGON installs and configures their development environment.
We also install the following programs on new machines.
sudo port install subversion
sudo gem install -y rspec
- ...amongst other gems that are needed on specific projects
Until next time… have fun!
1 Rumor: Mac OS X Leopard will give Terminal.app tabs! (see screenshot)
Older posts: 1 2