We have a WordPress install that has a different config file for Live, Test, Dev. I understand how to get Git to ignore the wp-config.php
file, but I want a different WP-config file in each of the branches. So that when a developer switches to Dev, it will use the database settings for Dev.
My process, is:
put live site into master.
add .gitgnore
commit
create new Dev Branch
Following this procedure, it means that I can no longer update the Dev branch with the Dev Config Details for other users to use.
Can anyone advise on how to do this please?
I understand, that you want to have different wp-config files in your branches, but they should not be merged, when you merge a branch into master.
I can think of three solutions to your problem:
You could put them into your branches and not merge them into master, but do cherry-picking instead.
You could put them into your branches and commit the correct file after every merge.
You could keep the files out of your repo completely (via .gitignore) and use the "post-checkout" hook to copy/link the correct file into the working-directory after every checkout.
The first two have the advantage, that your files are in the repo, but merging/correcting gets ugly.
The second is a bit of shell-hacking and everyone that has checked out the repo has to put the hook in his .git/hooks directory. Additionally, you probably need different scripts for windows and linux systems.
Further reading:
Git conditional files
What I have done in the past is commit the wp-config file, but extract the db connection info into another file and include it in wp-config. Then you can have files in source control like db-conn.dev, db-conn.prod and use a build tool like Grunt or Gulp to create a task that generates a db-conn.php file that gets included in wp-config. The generated file would not be in source control.
Here is an example of a gulp task to generate a config.php from config.dev
gulp.task('swapEnvConfigDev', function(){
gulp.src('./env-config/config.dev')
.pipe(rename('config.php'))
.pipe(gulp.dest('./env-config/'));
});