views:

379

answers:

4

I've got a project that I'm deploying to heroku. The source code tree includes a bunch of mp3 files (the website will be for a recording project I was heavily involved with).

I'd like to put the source code for it up on github, but github has a 300 MB limit on their free accounts. I don't want to use 50 MB of my limit on a bunch of mp3 files. Obviously, I could add them to the .gitignore file to keep them out of my repo.

However, I deploy to heroku using git push heroku. The mp3 files must be present in the branch I push to heroku so that they get get deployed.

Ideally, I'd like to .gitignore the mp3 files in my local master branch so that when I push that to github, the mp3s are not included. Then I'd keep a local production branch that has the mp3s committed rather than ignored. To deploy, I would merge master into production, and then push the production branch to heroku.

I can't get this to work right.

Here's an example of what I'm trying to do...

$ git init git-ignore-test
$ cd git-ignore-test
$ echo "*.ignored" >> .gitignore
$ git add .gitignore && git commit -m "Ignore .ignored files"
$ touch Foo.ignored

At this point, Foo.ignored is ignored in my master branch, but it's still present, so my project can use it.

$ git checkout -b unignored
$ cat /dev/null > .gitignore
$ git add Foo.ignored .gitignore && git commit -m "Unignore .ignored files"

Now I've got a branch with these files committed, as I want. However, when I switch back to my master branch, Foo.ignored is gone.

Anyhow got any suggestions for a better way to set this up?

Edit: just to clarify, I want the mp3 files to be present in both branches so that when I run the site locally (using either branch) the site works. I just want the files ignored in one branch so when I push to github they are not pushed as well. Usually .gitignore works well for this kind of thing (i.e. keeping a local copy of a file that does not get included in a push to a remote), but when I switch to the branch with the files checked in, and then back to the branch with the files ignored, the files vanish.

+1  A: 

Have you tried having .gitignore be different in your branch?

You should be able to ignore what you want based on the branch you are in as long as the files are not tracked on that branch.

kEND
I've tried that. If you look at the commands I posted above you'll see that's exactly what I did. The problem is that when I switch from the branch with the files checked in to the branch with the files ignored, git discards the files. I want to keep the mp3s in my master branch so the site works properly in dev mode, even though the files are ignored.
Myron
A: 

Can you commit and push from Heroku?

e.g. Add the audio, push them to github and into heroku, remove the files on the working copy on Heroku. Remove the audio from the repo but not from the disk, then push that change back to github.

Tom
A: 

I would strongly advise considering putting those MP3 files on S3. Having them be part of your Heroku push (and thus part of your Heroku slug) will greatly slow down your dyno startup time. Since Heroku uses EC2, if the files are on S3 and are only accessed by your app (if users aren't directly linked to S3) you won't even pay any bandwidth charges, only the charge to store 50MB.

David Dollar
+1  A: 

I wrote a blog post on how to effectively use the excludefile for different branches, like one for public github and one for heroku deployment.

Here's the quick and dirty:

$ git branch public_viewing
$ cd .git/
$ touch info/exclude_public_viewing
$ echo "path/to/secret/file" > info/exclude_from_public_viewing 

then in the .git/config file add these lines:

[core]
excludesfile = +info/exclude


[local "public_viewing"]
excludesfile = +info/exclude_from_public_viewing

Now all the global ignore stuff is in the info/exclude file and the branch specific is in the info/exclude_from_public_viewing

Hope that helps!

http://cogniton-mind.tumblr.com/post/1423976659/howto-gitignore-for-different-branches

Cognition.Mind
Fantastic. I never new about `excludesfile`. Thanks!
Myron