Setting up Git for Development and Test Branch wit

2019-08-12 03:13发布

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:

  1. put live site into master.

  2. add .gitgnore

  3. commit

  4. 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?

2条回答
Explosion°爆炸
2楼-- · 2019-08-12 03:55

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:

  1. You could put them into your branches and not merge them into master, but do cherry-picking instead.

  2. You could put them into your branches and commit the correct file after every merge.

  3. 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

查看更多
Luminary・发光体
3楼-- · 2019-08-12 03:56

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/'));
});
查看更多
登录 后发表回答