For some while, I’ve used git to manage multiple copies of apps for development, testing and production and I’ve always struggled to handle anvil.yaml properly.
I first asked a question on the subject back in 2017 and I followed it up a few days back with a further suggestion.
I think I may finally have found a solution I’m happy with:
- Create a copy of app using the anvil clone link (Let’s call the new copy dev-app)
- Use git clone(with the url for app) to create a local repository
- Use git remote add(with the url fordev-app) so that the local repository can access both copies of the app at anvil
- Run git update-index --skip-worktree anvil.yamlin that local repository
Now, we’re going to use git attributes and a git merge strategy to ensure that anvil.yaml is not touched when we merge changes from one branch to another:
- 
Create a git attribute by adding anvil.yaml merge=ignoreeither to a new file named.gitattributes(at the root of your repository) or to a new file calledattributesin the existing.git/config/infofolder. With the former, you also need to add, commit and push that new file so that anyone you might be collaborating with also gets that change. With the latter, it’s entirely local and nobody else will ever see it.
- 
Create a git merge strategy by using git config --local merge.ignore.driver true(this uses the Posixtruecommand so it will work on Linux and OSX. I have no idea what the windows equivalent might be).
The repository is now configured to leave anvil.yaml untouched for any conflicting changes when branches are merged. However, git would still merge non-conflicting changes and we don’t want those either. The fix is to ensure that there will always be a conflicting change:
- Checkout the master branch from appand add a comment line to the top ofanvil.yaml(I use something like# Config file for production app
- Add, commit and push that change
- Checkout the master branch from dev-appand add a similar but conflicting comment line toanvil.yaml(e.g.Config file for dev app).
- Add, commit and push that change
You can now use tracking branches in the local repo to make changes and push/pull them to the relevant copy of the app at anvil.
If you merge changes from one branch to another, git will ignore anvil.yaml entirely!
NOTE If you make changes within anvil.yaml that do need to be merged (e.g. changes to data tables), you’ll either need to handle that manually or temporarily remove the git attribute.