Rails on the Run

Rails experiments by Matt Aimonetti

Browsing Posts tagged git

As you’ve probably heard, Rails now moved to its own GitHub repo.

If, like me you were a heavy piston user, you are wondering how you will be able to do the same thing if you switch to git.

First off, you need to know that Piston will soon support git. As a matter a fact it already does. At least you can download a beta version from François’s blog.

You can also go with giston/braids which was meant to make the svn/switch easy on you. I heard rumors that evilchelu might not keep on developing this project. You might want to check with him.

Personally I didn’t really like using any of these solutions. Rails also came with its’ own approach. (rake rails:freeze:edge)

When I recently worked on Merb’s freezer, I discovered the power of git submodules.

Submodules allow you to import “modules” from other git repos inside your own repo. Basically they do what piston does for SVN, apart that submodules are built-in git. Of course it has an expected limitation, you can only add git submodules.

The good news is that Rails moved to git and now you can “freeze” Rails as a submodule and update really easily!

First thing first, you need to move your project to git. If you are not confident it’s a good move yet, you can use “git-svn”. However, I would personally recommend you don’t. I did that for few months and when I finally moved to git only, it was a pain to restructure the entire path of the app.

Anyways, let’s say you created a new github project and if still wish to use git svn do:

1
2
3
4
$ git-svn import svn://path-to-your-svn-repo project-name
$ cd project-name
$ git remote add origin git@github.com:mattetti/project-name.git
$ git push origin master

Your project is now under git, but if you pistonized Rails, you can’t update it anymore :(

Do not fear my dear friend and do as follows:

1
2
3
4
5
6
$ rm -rf vendor/rails
$ git commit
$ git submodule add git://github.com/rails/rails.git vendor/rails
$ git submodule init
$ git commit
$ 

That’s it you are done :)

Next time you want to update just do:

1
2
3
$ cd vendor/rails
$ git remote update
$ git merge origin/master

or you can also do

1
2
$ cd vendor/rails
$ git pull

(yes, each plugin acts a a normal git repo)

A quick note for gitHub users. If you browse your repo you won’t see the vendor/rails folder and might freak out. Don’t! Git is smart and wants to stay slim, instead of copying the files over, it just creates a reference to the original repo. If you try to pull your project in another folder you will see that the Rails folder gets created as expected.

Personally, when plugins are not available in a git repo I usually do a simple svn export to my project vendor’s folder. If I need to modify one of these plugins, I just import it to github and work on it from there.

You might still want to stick to Piston or Braids and that’s fine, but now you won’t have an excuse not to switch to Git :)

UPDATE: I just found out that Graeme wrote a nice detailed post about tracking plugins using git, check it out

I started moving some of my projects to GitHub.

Here is my GitHub account.

Projects moved to GitHub:

I’m planning on moving GoogleCharts, RandomWordGenerator and some not released stuff to GitHub so people can have fun forking my projects.

Git and GitHub are the new cool things. GitHub is planning on setting up a gem server while they are already offering tarball download and a post-receive hook. (they also plan on becoming myspace for geeks, but that’s another story)

Do you have to switch to git and github? Honestly, …no you don’t..
Git can act as SVN, but let’s be honest, if you switch to a new SCM it needs to do more. I’ve been using Git for a couple of months and even though I still don’t have a full understanding of this SCM, I really enjoy using it.

So, get over it, learn on your own or purchase this excellent peepcode

Email me to get a GitHub invite (Tom and Chris gave me some invites for readers) or/and try Gitorious.

The fact that some major players (Topfunky, technoweenie, Chris & PJ, jnunemaker and major projects such as capistrano, vlad the deployer and Merb use and support Git is a sign that it’s the next big thing.

Also, I believe that a lot of developers will also be motivated to move their plugins/gems to GitHub because they simply can’t always maintain their own libs and/or just hope people will fork their project and contribute back.

If you don’t know about git and github yet, it’s time you clean up your RSS feeds and find some good source of information.

Github is used by the Merb core team and I’ll show you how to use github to fork Merb, make your modifications and “submit your patch”.

This is the exact reason why github is simply awesome, it makes forking projects just super simple and submitting changes even easier.

First thing, you need to have a github account, if you don’t have one yet, email me, I have a couple of invitations left, otherwise, just wait until github gets public.

Now, let’s go to Merb’s repository and fork Merb-core by clicking on the fork button.

fork merb

Actually, for this example, I’ll fork merb-plugins because I want to improve the ActiveRecord rake tasks.

Because I forked merb-plugins, I now have my own forked repo: !my forked repo

I’ll start by checking out/cloning my forked repo locally.


git clone git@github.com:mattetti/merb-plugins.git

!git clone

Great I can now make my own changes…. but wait, what if the merb core team makes a change to the code? Well, I need to track their changes. Here is how:


git remote add coreteam git://github.com/wycats/merb-plugins.git

FYI, it adds the following to edit .git/config:

1
2
3
4

  [remote "coreteam"]
  url = git://github.com/wycats/merb-plugins.git
  fetch = +refs/heads/*:refs/remotes/coreteam/*

then


git fetch coreteam

and finally


git checkout -b coreteam coreteam/master

You can now track the latest change and merge them with your branch. Note that you can also track other forks and merge some other changes. (just that feature is worth using git)

Alright, now you can do your stuff, and push your local change to your remote repo at github.

Once you are done, you can simply click on the “pull request button”

pull request button

fill up the form and select the recipient. (wycats in this example if you want him to merge your changes into the official version of Merb).

pull request

p.s: The github guys are working on a gem to make our loves easier, give http://github.com/defunkt/github-gem/tree/master a try. I’ll post about the gem when it will be a bit more stable.