Reputation: 157
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
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
The first is the workdirectory
The second is the production directory that I create separately
In workdirectory directory:
-now the sensitvefile will be ignored, let's go to production repo that I created earlier
git remote add github remoteGithubUrlHere.git
git remote add heroku remoteHerokuUrlHere.git
add a merge driver called ours in global git config
git config --global merge.ours.driver true
add exclusion in heroku-branch
git checkout heroku-prod
add ".gitignore merge=ours" to .gitattributes
add ".gitattributes merge=ours" to .gitattributes, then commit changes.
git checkout master
git pull github master
git checkout heroku-prod
git merge master
git checkout heroku-prod
git push -u heroku heroku-prod
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:
Upvotes: 1