I have a rails 3 application in local. I created reposority and i know the basics of git like git. I am using git for heroku but i haven't push my application to public place before. What i want to learn is :
Which files should i add to git ignore? Because i have some personal passwords and keys in environments.rb and also have some keys in initializers.
If i add some files in git ignore, i guess it will be a problem for people who clones it, because some files will be missing.
I will also keep on working on my application, i can always add new keys to environment.rb or somewhere else. Do i have to clone(branch) my application? I heard something "branch, master" but i have no idea about these terms?
The idea of gitignore is that often there are temporary files, or files that are specific to your IDE. They add nothing to source code, and sometimes they contain sensible information about your machine that you probably don't want to share.
This repo on github is a nice collection of gitignore templates:
https://github.com/github/gitignore
Rails template is available: https://github.com/github/gitignore/blob/master/Rails.gitignore
EDIT
If you have files with you current configuration, which are important for your app, remove all the sensitive information from them, check them in, and after that modify gitignore file.
If you have already checked in a file with passwords, use this manual: http://help.github.com/removing-sensitive-data/
Create a .gitignore file in your root directory, and add all the files which you do not want to track. Make sure those files are not already tracked. If they are, delete the files, commit the change to the git repository, and then add those files to your .gitignore file.
Your .gitignore file could look something like this
log
db/*.sqlite3
db/*.sql
*.tmproj
tmp
coverage
config/database.yml
*~
\#*\#
.\#*
target/*
**/.DS_Store
.DS_Store
Related
I managed to delete to following files with git clean in my rails app:
Removing .DS_Store
Removing .bundle/
Removing config/application.yml
Removing db/development.sqlite3
Removing log/development.log
Removing public/system/profiles/avatars/000/000/011/
Removing public/system/profiles/avatars/000/000/012/
Removing tmp/
Are there any chances of getting back these files somehow or being able to copy from somewhere else? (Git deletes files permanently, so trash is empty. I also tried w/ disk drill but id didn't work out either.)
How can I protect my gitignored files properly to avoid these kinda situations in the future? Should I copy them sometimes or there are other programs to handle this?
Do I have to recreate my rails app or somebody knows a better option?
I think you can try to find these files in previous commits.
Next time remove using command git rm --cached file_name
I was able to pull it off. I ran bundle install (creates the files within .bundle) and reinstalled sqlite and figaro. After that I ran rake db:migrate which created the development.sqlite3 file. I lost the development data, but it is not a huge problem at all. For figaro I had to retype the keys and passwords (Sendgrid, Stripe, etc.) into the new application.yml file. Temporary and log files don't seem to be important. Thanks for the answers. This $git clean is pretty dangerous, watch out!
I have several PSD files stored in my images folder. It's nice to keep these files there for development, but I don't want them to be served. Is there a config somewhere that would allow me to prevent a filetype from being precompiled?
Your best bet might be to exclude these files during deployment. For example, with Heroku if you add a .slugignore file to the root of your project you can exclude certain files from being included. This also has the added benefit of decreasing spin up times on Heroku. An example configuration would be:
*.psd
*.pdf
doc
You should be able to do something similar with Capistrano.
Edit:
This post shows how to do something similar for Capistrano deploys:
Excluding files from being deployed with Capistrano while still under version control with Git
I'm getting a lot of untracked / modified files that are like this in my Rails app:
db/sphinx/development/user_core.spa
db/sphinx/development/user_core.spd
db/sphinx/development/book_core.sph
db/sphinx/development/book_core.spi
db/sphinx/development/book_core.spp
db/sphinx/development/book_core.sps
etc.
Should I include these when I commit and push in git, or should I put db/sphinx/development/* in my .gitignore file?
--EDIT after getting answer below--
I ended up adding this to my .gitignore file...
# Ignore certain Sphinx files
/db/sphinx/*
/config/*.sphinx.conf
...and then doing what is recommended here: Ignore files that have already been committed to a Git repository
You should add those to .gitignore. They're similar to database files. The only sphinx specific file I think you might want to check in is the config/sphinx.yml files, assuming it doesn't contain any sensitive information.
I have a repository with a rails app in the production Server.
In the repo there is the .gitignore file:
...
config/database.yaml
...
Every developing client have a cloned repo with different config/database.yaml.
My problem is this:
database.yaml is in .gitignore, then when I run git clone (on the server) the database.yaml will not be created, but I need it.
I thought than I am doing wrong something.
Can you see where is my mistake ?
thank you,
Alessandro
In my projects, I usually make a copy of a usable database config in a database.example.yml, then when someone clones the projects, copy the database.example.yml to database.yml and make the needed changes.
(here is a copy of my original answer to your first question)
You don't version the right file.
You should version:
a database.yaml.template
2 files (one for server values, and one for generic client values)
1 script able to build database.yaml on the checkout
That script would be called by the smudge step of a filter driver.
The resulting database.yaml would be "private" (never versioned/pushed or pulled), and can be modified at will.
keep a template like database.example.yml as robertokl suggests
when you deploy your application to production server you should be using something like capistrano and part of your capistrano recipe(script) will be to rename that file or to place the correct database.yml file in the config dir
All these database.yaml files have something in common: you can commit a base configuration, and let all your developing clients maintain a fork of it in their own branches with appropriate settings filled in; they can rebase on top of the base configuration in the master branch whenever it gets updated.
aleds - it's generally a bad idea to have your database.yml in a repository which is why you see it in .gitignore. robertokl is right about providing a template file.
I created a hello world app with rails HelloWorld command. I ended up with many directories:
app
config
db
doc
lib
log
public
script
test
tmp
vendor
Should all this be under sources control? What would be a good default .hgignore file for a Ruby on Rails app folder?
.bundle
db/*.sqlite3
log/*.log
tmp/*
.DS_Store
.orig
log/*
tmp/*
your dev database under db
can be ignored to start with.
The general rule is that if you've typed it by hand it should be in source control. If there are some scaffolding files that you didn't type but that can't be easily generated by your build system and don't often change, add them too. Avoid adding files that can be generated from other added files and non-mergeable files that change often.