Mosta
Mosta

Reputation: 157

Heroku, Github and Asp.net core, How to manage appsettings.json?

How can I push asp.net core project to Github and Heroku, but only push appsettings.json to Heroku?

I have tried GitFlow model, Added appsettings.json to .gitignore in all branches, But one that I named heroku_app and configured --set-remote-to=heroku/master, therefore Github will not see it as long as I never merge it to branch Github can see.

however this didn't work as intended because everytime I implement a feature to master, then git checkout heroku_app, then git merge master, A .gitignore merge conflict appears, not only that but git removes my appsettings.json file.

If only I can set a rule so that never remove appsettings.json on git checkout or git merge, and rule so that never change .gitignore on branch heroku_app, I would be happy !

Upvotes: 2

Views: 1004

Answers (1)

Mosta
Mosta

Reputation: 157

I have figured out a way to solve the problem I had, simply put I separated production repo and workdirectory repo, then in production repo added two branches one to pull from github and other to push to heroku, then added merge exclusion rules from pull branch to production branch here is the steps

=== Creating two separate git repos

The first is the workdirectory

The second is the production directory that I create separately

In workdirectory directory:

  1. Clone the github repos
  2. add "path/sensitvefile" to .gitignore file in all branches, commit and push
  3. put the sensitvefile in workdirectory and make sure that git didn't detect any change by `git status

-now the sensitvefile will be ignored, let's go to production repo that I created earlier

  1. create a heroku-branch called heroku-prod
  2. create a master-branch called master
  3. add remote github repo git remote add github remoteGithubUrlHere.git
  4. add remote heroku repo git remote add heroku remoteHerokuUrlHere.git

=== adding merge exclusion in heroku folder

  1. add a merge driver called ours in global git config

    git config --global merge.ours.driver true

  2. add exclusion in heroku-branch

    git checkout heroku-prod add ".gitignore merge=ours" to .gitattributes add ".gitattributes merge=ours" to .gitattributes, then commit changes.

publishing steps

1- pull from github

git checkout master git pull github master

2- merge master-branch to heroku-branch

git checkout heroku-prod git merge master

3- push to heroku

git checkout heroku-prod git push -u heroku heroku-prod

======= Important Note

any change in .gitignore or .gitattributes will be ignored on merge master-branch to heroku-branch, so if there any change in this file, the change have to:

  • Be manually edited.
  • Or Temporarily remove merge exclusion in '.gitattributes' file and keep sensitive files away then merge, then return merge exclusion in '.gitattributes'

Upvotes: 1

Related Questions