5

I'm trying to keep my static files in a separate branch so that I can keep them from merging into my master brach (on Heroku, your application's slug needs to stay small). I don't want to ignore my static files, because I want to keep them inside my "devel" branch.

Ideally I'd like to keep test.db blank and my entire public folder blank in the master branch.

So, can I create an 'overlay' onto a branch? Can I prevent certain files/directories from merging into my master branch?

arbales
  • 5,466
  • 4
  • 33
  • 40
  • @Jonathan: Thanks for the spellcheck. – arbales Sep 15 '09 at 07:10
  • Note: this is one solution, but others may propose some other organization to achieve the same result. – VonC Sep 15 '09 at 07:22
  • As I'd suspect. I'd certainly be interested in hearing other interesting solutions, even just for my own/other's edification. – arbales Sep 15 '09 at 08:42
  • Is it appropriate to mention that in the question – should I maybe change the title to 'How would you separate files in Git'? – arbales Sep 15 '09 at 08:45
  • If you set a `.gitattribute` in the *parent* directory of public, with the pattern `public/*`, that should be enough. – VonC Sep 20 '09 at 10:05
  • That's what I figured, but git seems to ignore it. It also ignored .gitattribute -- I needed to make it .gitattributes – arbales Sep 20 '09 at 16:02

2 Answers2

8

You could define those same static files on your master branch but:

Since that .gitattribute would not be define on other branches, the merge of those files would proceed normally.


The idea is to define a .gitattributes file in the directory of those static files on the master branch with the following content:

myStaticFile1 merge=keepMine
myStaticFile2 merge=keepMine
myStaticFile3 merge=keepMine

Those three files will always keep their local content (which is empty on master) when merging to master.

You will have to define a merge driver (here called "keepmine"). See the linked question for that script.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Could you explain in a little more detail? I've not used attributes before and the link isn't 100% straightforward. – arbales Sep 15 '09 at 07:05
  • Also, I don't seem to be able to define wildcards, I tried public/* merge=keepMine, which didn't work. I also tried removing the directory and touching it, making a file, but Git complains and makes another version of public on merge. – arbales Sep 20 '09 at 03:01
0

Add the files to .gitignore in master. When you checkout devel, .gitignore will change and won't ignore them anymore. (Note that if you run git clean -x, the files will be overwritten.)