1

I have a project with Ruby on Rails and local files, images in this case, are stored in the path /public/system. I included that line in .gitignore but every time I push changes to the remote repository the images are uploaded to github anyway.

Why?

I just want this folder and its content not to be uploaded to github, but I do want to keep the files in my local repo.

This is my .gitignore file, it's just the default content, I added the last line:

# 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 the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

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

/public/system
dabadaba
  • 9,064
  • 21
  • 85
  • 155
  • 1
    possible duplicate of [Making git "forget" about a file that was tracked but is now in .gitignore](http://stackoverflow.com/questions/1274057/making-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – nwinkler Aug 10 '15 at 13:34
  • I saw that answer, but I am not asking that exactly, I am updating my post to clarify – dabadaba Aug 10 '15 at 13:39
  • you _are_ asking that exactly. What doesn't work about the top answer there? It is literally the same command as the answer you just selected. – ABMagil Aug 10 '15 at 13:45

1 Answers1

0

Once one of the files is committed (remember that git doesn't care about folders), adding them to the .gitignore file is not retroactive. You will have to remove them using this command

git rm --cached public/system

It will only remove them from git index, not in your local modifications therefore the folder will still exist in your file system.

axelduch
  • 10,769
  • 2
  • 31
  • 50
  • That worked! However, what if I run `git add -A .` again? Would that start keeping track of the folder again? I guess it would right? What can I do to avoid this? – dabadaba Aug 10 '15 at 13:44
  • Once you've committed the 'deletion' outlined by @aduch and your `.gitignore` file, they should be ignored permanently. You can test this by using `git status` - they shouldn't show up as untracked files. – Smigs Aug 10 '15 at 14:25