Every time, once you create a new Rails application on a Git resipotary, you have to create a .gitignore file to make sure that Git will ignore certain files that it should not keep track. For examples,
log/*.log tmp/**/* .DS_Store doc/api doc/app
These are the static and dynamic files that Rails creates. So, I create a simple ruby script into my bin directory so that I can just use a simple command to create this .gitignore file easily.
Firstly, in terminal, under your home directory, change your directory into “bin” subdirectory. Create a text file called “gitignore”. Inside the file, use your favorite text editor, write:
#!/usr/bin/env ruby
# create .gitignore
f = File.new(".gitignore", "w")
f.write("log/*.log\n")
f.write("tmp/**/*\n")
f.write(".DS_Store\n")
f.write("doc/api\n")
f.write("doc/app\n")
f.close
puts ".gitignore created."
Save the file and close your text editor. Then, chmod the “gitignore” file:
chmod a+x gitignore
So, now, every time, after you create a Rails application with the “rails” command, change directory into your Rails application’s directory, fire the “gitignore” command, the .gitignore file will be created automatically.
Happy Gitting.