9

I am certain two branches of my Git repo should only ever be different in a single file. The simplest way to ensure this is to do all work in branch1, and merge it into branch2 whenever I switch to it (wrapped into a shell script, so I only need one command per switch). However, is there a way to do this with even less work?

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487

1 Answers1

8

Yes, use a git filter driver, with a smudge script intelligent enough to:

alt text

But the question is: do you need two branches at all?
If this is a config file, as mentioned in "Git: how maintain (mostly) parallel branches with only a few difference?", storing templates might be better. That same question proposes other alternatives.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    +1 Finally, out of all the "duplicate" related posts on this site, @VonC provides the correct way of doing it. Perhaps harder at first, but its not a hack like the rebase methods. – Richard Le Mesurier Apr 04 '14 at 17:02