Rails which files to ignore for GIT
Asked Answered
H

7

55

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?

Hamelin answered 8/3, 2012 at 10:43 Comment(1)
Rails should have generated a .gitignore file for you with the most common non-source-control files included alreadyJug
U
83

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

Unfeeling answered 8/3, 2012 at 10:49 Comment(3)
This answer is incredibly awesome.Highstepper
I need a "favorite answer" star system.Mount
The Rails file under this Repo is at github.com/github/gitignore/blob/main/Rails.gitignoreSoulsearching
C
13

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

Casaleggio answered 8/3, 2012 at 10:50 Comment(1)
thx. i need to look into that, since it was not working. Weird.Hamelin
L
2

.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

Loria answered 8/3, 2012 at 11:11 Comment(0)
F
2

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
Foreyard answered 26/1, 2015 at 3:1 Comment(0)
T
1

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).

Tenatenable answered 8/3, 2012 at 10:47 Comment(2)
must be hidden @RogierFilmer
@zack, nah it was not there (i know hidden are staring with . [dot]).Hamelin
R
0

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.

Reno answered 21/7, 2023 at 6:42 Comment(0)
A
0

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
Advisedly answered 16/6 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.