In a git repository I have two files: config/conf.yaml.sample
(which is tracked by git, but it's ignored when my program is launched) and a copy of it called config/conf.yaml
(which is ignored by git, but it's read when my program is launched).
When I switch from branch A to branch B I always have the same configuration file (because config/conf.yaml
is untracked) and that means, for example, that each branch relates to the same database, same ports, and so on.
I want to keep a different config/conf.yaml
for each branch, so that it changes when switching branches, but I don't want to have git track it (e.g. because it contains the name and password to access the database).
How can I do it?
It seems that Git's post-checkout hook is right up your alley:
The following script (which must be made executable) should get you started; modify it to suit your needs and save it as
.git/hooks/post-checkout
: