#96
Mar 10

Git on Rails

Git has been getting a lot of buzz lately, and for good reason. It's an excellent SCM which in many ways is more simple and powerful than subversion. See how to set up a Rails project with Git in this episode.
Tags: tools
Download (7.8 MB, 5:56)
alternative download for iPod & Apple TV (6.8 MB, 5:56)
Resources
# commands
git init
git status
git add .
git commit -a
touch tmp/.gitignore log/.gitignore vendor/.gitignore

# .gitignore
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3

28 comments:

jonuts Mar 10, 2008 at 02:56

heh i was scourging the entire internets for this exact screencast last night. thanks!


Matt Beedle Mar 10, 2008 at 03:03

Git does look pretty good, but so far subversion has done everything I have needed it to.


Senthil Nayagam Mar 10, 2008 at 04:03

Hearing good things about GIT for quiet some time but, lack of windows support is holding us back.

till we get some native binaries(not cygwin), we would remain with subversion.


Pete Yandell Mar 10, 2008 at 05:52

I use the following little "git-rails" script to take a new Rails project and initialise it as a git repository.

#!/bin/sh

git init

cat <<EOF > .gitignore
.DS_Store
log/*.log
tmp/**/*
db/*.sqlite3
coverage
doc/app/*
EOF

find . -type d -empty -exec touch {}/.gitignore \;

git add .
git commit -a -m "Initial import."


Jo Potts Mar 10, 2008 at 06:06

Thanks Ryan, another great screencast.

I'd been holding back for the same reason Matt gave. The try-something-new temptation is strong though... so time to give it a try me thinks!


Martin Ström Mar 10, 2008 at 06:11

Another great screencast.
One thing, you dont need to use `git add .` if you commit using the -a option. It will automatically add all modified files to the commit.


Claudio Caseiro Mar 10, 2008 at 06:21

Martin, I think you are wrong about using "git add .". To add new files to repository (index) you need to use "git add ." before commit.
"git commit -a" only adds modified files that are already part of the repository, not new files. So after "git init", or every time you add new files you should use "git add ."


Martin Ström Mar 10, 2008 at 06:33

Yes, sorry. I meant that that "git add ." is only needed the first time for new files and the following times (for existing files) should "git commit -a" be enough.


Carl Mar 10, 2008 at 07:52

A future screencast I'd love to see would be about how to do testing when you are using Restful Authentication. I'm missing something (I hope) because it seems to be a bear to do, and your sceencasts always help with those sort of problems.


Luis Lavena Mar 10, 2008 at 12:06

@Senthil:

Better Git support is built into msysGit:

http://code.google.com/p/msysgit/

Still, lacks git-svn support due perl bindings, but is usable :)

In any case, the steeped learning curve of Git (ala: the bad UI design it has) make me stay away from it and keep using bazaar as SCM.


Gav Mar 10, 2008 at 15:56

I feel a little silly asking, but what does ** mean?

Ryan and Pete Yandell (in a comment) used it in their .gitignore files

tmp/**/*

Thanks


Nicolás Sanguinetti Mar 10, 2008 at 23:31

@Gav: something/**/* will go down all the subdirectories of 'something' and select all the files inside.

@Ryan, Pete: shouldn't you also ignore the schema.rb?

In my personal experience, git is the best thing that happened to my workflow since rails :)


Stephen Wooten Mar 11, 2008 at 01:08

Prior to getting my new mac, I was on windows and was playing around with a windows port of Git called 'Git Bash'

http://code.google.com/p/msysgit/

and a little installation walkthrough:

http://kerneltrap.org/Linux/Git_on_Windows

--Good luck guys!


Stephen Caudill Mar 12, 2008 at 11:19

I'd highly recommend staying away from braid for the time being. In my experience it's been very buggy and has out and out thrashed a particular project badly enough that I had to re-import it form SVN.

Piston has forthcoming git support, so I'll be waiting for that.


Jörg W Mittag Mar 12, 2008 at 18:20

Hi,

I just wanted to quickly point out that you are putting the ".DS_Store" into the wrong .gitignore file, IMHO. You put it into the ToDo app's .gitignore file, but actually it's not specific to the ToDo app, it is specific to your development environment (MacOS X). So, it belongs in your systemwide .gitignore, not the project-specific one.

jwm


Diego Mar 13, 2008 at 03:23

Git rocks!

as well as Linux and Linus Torvalds ;)

thanks for this screencast


Rajesh Duggal Mar 14, 2008 at 08:55

There's git support for script/generate in edge.

http://dev.rubyonrails.org/changeset/8772

e.g. script/generate -g

Cheers,
Rajesh.


James H Mar 14, 2008 at 16:08

A note to those using Autotest: you might want to add an exception to ignore your '.git' folder, lest you wish Autotest to slow to a halt.

See http://blog.davidchelimsky.net/articles/2008/01/15/rspec-1-1-2-and-zentest-3-8-0


Diego Viola Mar 17, 2008 at 02:24

This is also very nice to have it as a reference.

http://zrusin.blogspot.com/2007/09/git-cheat-sheet.html


Gavin Baker Mar 18, 2008 at 08:07

@Nicolás: how is that different to something/*/* ?

Gav


devon Mar 18, 2008 at 16:34

Should we add schema.rb in the .gitignore?

My .gitignore contains:
db/*
!db/migrate

and also

public/cache/**/*


Ryan Bates Mar 19, 2008 at 16:36

@Stephen, thanks for the input. I removed Braid from the list of links for now. Looks like Git support for Piston is coming along nicely! Can't wait!

@Jörg, I agree, excellent point!

@Gavin, I believe ** will traverse the directory to multiple depth, but someone please correct me if I'm wrong.

@devon, I like to keep my schema.rb file under version control so if someone downloads the projects they can just run db:schema:load rather than running all the migrations. The comments at the top of schema.rb file recommend doing this as well.


Caleb Mar 22, 2008 at 16:49

There's a pretty comprehensive git textmate bundle available:

http://blog.macromates.com/2008/git-bundle/

Make sure you set the TM_GIT textmate environment variable to the path of your git binary (/opt/local/bin/git for macports for example)


jujudellago Mar 28, 2008 at 02:32

Used to work with CVS, got really excited with SVN as replacement, but as linus said, they got it all wrong from the begining....

it's not a technical screencast, but I recomand that video http://www.youtube.com/watch?v=4XpnKHJAok8

a bit long, but very interresting, fun presentation at google talks


Ayyanar Mar 29, 2008 at 04:45

Any IDE supports GIT to check-in check-out directly like RADRAILS supports SVN


Abizer Nasir Apr 13, 2008 at 15:28

You might not always want to use the -a option with commits.

I like the power of the index just having the state of the files when they were added. Using the -a option means that the index is updated with the current state of the file.


Kino May 03, 2008 at 07:24

Why not left the old version?


slothbear May 03, 2008 at 22:02

I have to admit I was a little confused about adding vs. the "-a" option vs. the index. And comments (in the Peepcode) about git tracking "content", not "files". Whaaaaa.

An article by Ryan Tomayko cleared it all up for me. It's a little more advanced. You might not need his actual technique, but it illuminates the topic of "adding".

http://tomayko.com/writings/the-thing-about-git

Add your comment:

(required)

(not displayed)

(SKIP THIS ONE)


(required)

subscribe:
sponsored by:
if you want to help:
required:
Get Quicktime Player