Mike
Mike

Reputation: 149

Separate gitignore files for Heroku and GitHub?

I have one file that is necessary for my heroku app but that I do not want in my GitHub repository.

Is there any way to have a .gitignore that is only used when pushing to GitHub?

Additionally, is there any other way that I can avoid pushing that one file to GitHub?

Upvotes: 4

Views: 1471

Answers (2)

Chris
Chris

Reputation: 136984

VonC's answer is good, but here's a bit more information.

Is there any way to have a .gitignore that is only used when pushing to GitHub?

.gitignore never comes into play with git push:

  • git push operates on commits, so if you want a file to be included in your Heroku build it must be committed
  • Git's ignore system only prevents files from being tracked; it has no effect on tracked files

You could theoretically maintain a long-running heroku branch that's kept up to date with master (or whatever your main branch is) but also contains your Heroku-only file, but in my opinion there's no reason to jump through those hoops. Just include your Procfile or whatever it is in your main repository. What harm is it doing?

Note that if you had the opposite situation, where you wanted to omit some tracked files on Heroku, you could use a .slugignore file:

If your repository contains files not necessary to run your app, you may wish to add these to a .slugignore file in the root of your repository. Examples of files you may wish to exclude from the slug:

  • Art sources (like .psd files)
  • Design documents (like .pdf files)
  • Test data

...

The .slugignore file causes files to be removed after you push code to Heroku and before the buildpack runs.

Upvotes: 1

VonC
VonC

Reputation: 1325137

If you have already tracked this file, removing it (and even ignoring it in a .gitignore) before pushing to GitHub will not remove it from the history of that pushed repository.

That means it is important to know why you do not want that file on GitHub.

If it is for security reason, because it includes sensitive information, you might have:

  • more work to do
  • to externalize that file outside of any local repository to be sure it won't be included.

More generally, no, there is no conditional/separate .gitignore for two different remote repository.

In your case, you might have to script your git push operation in order to play with, as in here, to play with git update-index --(no-)assume-unchanged <file>.

Upvotes: 1

Related Questions