Roger
Roger

Reputation: 7612

Rails which files to ignore for GIT

I created a GIT repo, locally. I now see a bunch of files i rather ignore for GIT check-in. This brings me to the question: is there any default .gitignore for Rails? Any best practices?

I think of tmp and log for sure. But are there any other files or folders i should consider?

Upvotes: 55

Views: 32070

Answers (7)

Andrew
Andrew

Reputation: 3969

This is the .gitignore file that was generated using Rails 7.1.3.4.

https://github.com/rails/rails/blob/v7.1.3.4/railties/lib/rails/generators/rails/app/templates/gitignore.tt

# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all environment files (except templates).
/.env*
!/.env*.erb

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep

/public/assets

# Ignore master key for decrypting credentials and more.
/config/master.key

This is the .gitattributes file that was generated.

https://github.com/rails/rails/blob/v7.1.3.4/railties/lib/rails/generators/rails/app/templates/gitattributes.tt

# See https://git-scm.com/docs/gitattributes for more about git attribute files.

# Mark the database schema as having been generated.
db/schema.rb linguist-generated

# Mark any vendored files as having been vendored.
vendor/* linguist-vendored
config/credentials/*.yml.enc diff=rails_credentials
config/credentials.yml.enc diff=rails_credentials

Upvotes: 1

mansoor.khan
mansoor.khan

Reputation: 2616

Here's the direct link to the Rails gitignore file. It is up I found this by a simple google search.

You can modify it as per your project/tools settings. I had to add .idea/ to it which is automatically generated by Rubymine.

Upvotes: 0

Ekin Koc
Ekin Koc

Reputation: 2997

Github has sample .gitignore files for almost any kind of project known to humanity in their github/gitignore repository.

There is one specifically for Rails: Rails.gitignore

Upvotes: 84

errakeshpd
errakeshpd

Reputation: 2562

Make use of this GITIGNORE.IO

### Rails ###
*.rbc
capybara-*.html
.rspec
/log
/tmp
/config/database.yml
/db/*.sqlite3
/db/*.sqlite3-journal
/public/system
/coverage/
/spec/tmp
**.orig
rerun.txt
pickle-email-*.html

# TODO Comment out these rules if you are OK with secrets being uploaded to the repo
config/initializers/secret_token.rb
config/secrets.yml

## Environment normalisation:
/.bundle
/vendor/bundle

# these should all be checked in to normalise the environment:
# Gemfile.lock, .ruby-version, .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc

# if using bower-rails ignore default bower_components path bower.json files
/vendor/assets/bower_components
*.bowerrc
bower.json

#Ignore pow enironment settings
.powenv

Upvotes: 2

Bijendra
Bijendra

Reputation: 10025

.git/info/exclude If you wish the exclude patterns based on repositories , you may instead put them in a file in that specific repository named .git/info/exclude or core.excludesfile

.gitignore is used to add files which you don't want to be tracked. If the file is already being tracked and you want to add to .gitignore. run git rm --cached filename

Upvotes: 2

beanie
beanie

Reputation: 1448

this is a gitignore from a relatively large Rails 3.2 app (created with Rails 3.1)

/.bundle
/db/*.sqlite3
/log/*.log
/tmp
config/database.yml
config/google_analytics.yml
.DS_Store
/nbproject/
public/assets/**

just the basic gitignore which comes with rails and added some developer specific stuff like Netbeans project stuff, the .DS_Store from OS X

and we don't like passwords in our repository, so we add all yml files with passwords to gitignore

we also added public/assets/** since we deploy our apps with capistrano and generate the assets during the deploy and push them to amazon

Upvotes: 13

Rails already generate a .gitignore file for you with good defaults. You think right, in fact the .gitignore generated by rails already ignores tmp and log file (and the DBs too).

Upvotes: 1

Related Questions