Improved Git Workflow for Handling anvil.yaml

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 for dev-app) so that the local repository can access both copies of the app at anvil
  • Run git update-index --skip-worktree anvil.yaml in 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=ignore either to a new file named .gitattributes (at the root of your repository) or to a new file called attributes in the existing .git/config/info folder. 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 Posix true command 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 app and add a comment line to the top of anvil.yaml (I use something like # Config file for production app
  • Add, commit and push that change
  • Checkout the master branch from dev-app and add a similar but conflicting comment line to anvil.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.

3 Likes

I’ve made a start on writing this up properly:

3 Likes

This looks great and really helpful thanks Owen. I’m gradually getting my head around it and your other posts are actually starting to make sense to me now too!

Once you’re happy with the Gist, it would be great to add it to the Wiki post on this forum, perhaps added as Level 12 piece?

All the best,
Peter