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?
Git stores all references under the . git/refs folder and branches are stored in the directory . git/refs/heads. Since branch is a simple text file we can just create a file with the contents of a commit hash.
You can have many branches in your repository, but only one of these will be "checked out" as the working-tree so that you can work on it and make changes. git worktree adds the concept of additional working trees. This means you can have two (or more) branches checked-out at once.
Branching allows each developer to branch out from the original code base and isolate their work from others. It also helps Git to easily merge versions later on.
Yes, use a git filter driver, with a smudge script intelligent enough to:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With