#96 Git on Rails
Mar 10, 2008 | 5 minutes | Tools
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.
heh i was scourging the entire internets for this exact screencast last night. thanks!
Git does look pretty good, but so far subversion has done everything I have needed it to.
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.
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."
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!
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.
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 ."
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.
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.
@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.
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
@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 :)
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!
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.
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
Git rocks!
as well as Linux and Linus Torvalds ;)
thanks for this screencast
There's git support for script/generate in edge.
http://dev.rubyonrails.org/changeset/8772
e.g. script/generate -g
Cheers,
Rajesh.
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
This is also very nice to have it as a reference.
http://zrusin.blogspot.com/2007/09/git-cheat-sheet.html
@Nicolás: how is that different to something/*/* ?
Gav
Should we add schema.rb in the .gitignore?
My .gitignore contains:
db/*
!db/migrate
and also
public/cache/**/*
@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.
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)
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
Any IDE supports GIT to check-in check-out directly like RADRAILS supports SVN
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.
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
anyone know if there is a plugin for git that i can use for eclipse? i've gotten used to right-click -> commit and team -> revert etc. and doing those things on the command line feels like a step backwards...
Git looks great, but can it work with deprec/capistrano/mongrel as well as subversion does?
As of this moment GiT users face the same problem that every earlier adopter does, a lack of compatibility and support in most ancillary tools. This, however will change over time and the decision of when to move to GiT may well be heavily influenced by what tool is considered most important.
In our case we recently moved from Trac to Redmine because we decided that the VCS was a more vital technology to our future efforts than the Project Administration System. As Trac support for GiT is very minimal and has not, to my recent knowledge, been slated for core implementation we decided to move PAS as well as VCS. Others will decide to stay on Subversion until their desired tools provide better support for GiT.
I have found GiT's UI, for the most part, simple and straight forward to use. I have zero experience with the the GUI's available but the command line instructions could ahrdly be simpler.
The whole structure of GiT is a marvel to consider. The insight of the designer is, for me, dumbfounding. One must consider that this entire project is really nothing more than an innovative combination of tools that have been present on most Linux distributions for years.
GiT's innovations have tremendous possibilities for OS fs security and data compaction in future Linux distributions. I believe that GiT is going to radically change computing. Consider the value of knowing simply by looking at the SHA1 value of the system whether or not any file in /etc or /var/share or /usr/local has been changed or needs to be updated!
The SVN folks themselves have conceded that the OOS community mind-share has committed to DVCS and that SVN will likely be the end of the line for centralized repository systems in OSS. Whether this means that GiT will be "THE" OSS DVCS is another issue.
Hi Ryan,
Thanks for your great rails screencasts.
I've small tip for the people who use "vim" as code editor. If you want to exclude ".swp" files, just add "*.swp" to your ".git/info/exclude" file.
for those that use capistrano, and had followed this screencast, make sure you DO NOT add the log/*.log and config/database.yml to your .gitignore file.
Capistrano will spit out error messages when you begin to migrate your db.
Learn from me :-)
Hi all,
I've tried out some cases for the .gitignore file. How this file have to be if I would exclude all file except two?
# .gitignore
*
!days.txt
!directory
But if I add a file to directory I get a message, that I have to use git add -f to add to the staging area. Could anyone help me?
@nerb -
If you use Capistrano, it pays to exclude the log files and database.yml from git, then create the files in the shared/ folder (that is shared between different releases) and then symlink them into your project.
The benefits of excluding those files from source control are huge when you have a handful of developers, each with a different machine configuration.
@nerb - A quick follow up. Add this to your deploy.rb:
task :after_update_code, :roles => [:web, :db, :app] do
run "ln -nfs #{deploy_to}/#{shared_dir}/config/database.yml #{release_path}/config/database.yml"
end
Simple question for noob.
I am trying to figure out the correct url for my capistrano deploy script for the local git repo this sc uses.
"git://localhost:3000/.git"?
Whatever i try gives me errors. I am on Leopard.
@Dnew: Try 'set :repository, "file:///Users/[path to project]/.git"'
Thanks for this great screencast. After seeing it, some might want to go to this short tuto I wrote. It explains why git is so useful and how to use it along with github and an open source project:
http://harryseldon.thinkosphere.com/2008/11/08/grand-gardening-with-git
(My name contains the active link)
One small suggestion to Pete's suggested script. I move the find script that inserts .gitignore into blank dirs BEFORE running git init. This avoids placing .gitignores into the .git directory. Harmless but not very clean.
Here's the gist
http://gist.github.com/141509
How do you automatically add new files? What is the point of adding a directory if the directory isn't monitored for new files?
How do you automatically add new files?
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...
Better Git support is built into msysGit:
A note to those using Autotest: you might want to add an exception to ignore your '.git' folder
Simple question for noob.,
How to use git in eclipse
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...
I had installed git a while back, but hadn't done anything with it. However, after fussing with Subversion branching/merging - I had fresh initiative to use git. This screencast really demonstrates ease in which to setup a rails project under git.
Thanks Ryan, you are providing a valuable service with RailsCasts!
The new Rails 3 binary will actually automagically create all the bare necessary .gitignore and .gitkeep files you may need. It does this by default, but you can opt-out of creating them by passing -G as an option on the command line.
If I'm repeating someone above, feel free to delete this, but instead of creating .gitignore files in the directories you want to add to the repo, you can just add them with:
git add -f tmp log vendor
Thank you How do you automatically add new files? What is the point of adding a directory if the directory isn't monitored for new files?
From now , i'll be the regular visitor of your web. Thanks , great info.
http://www.nsdlpan.co.in
This would be a good one to revise.
This would be a good one to revise.
Yeah would definitely love an update
a revised version would be great!
Yeah, I agree. It's a great introductory topic. But there are lots of things to cover.
So either a good topic for a long episode or a series of two. Or maybe I've written too many git-specific things?
Buen vídeo felicitaciones me gusto