How to persist custom posts, custom fields and styles on a Github repository?

ACF has two options for this:

  1. PHP / JSON exports
  2. acf-json

Method 1)

Go to ACF->tools->select field->export file / generate PHP.

If you choose generate PHP, you can copy the result into a .php file in your theme, which you then need to include. You cannot import PHP exports though ACF again: the fields will be available but you will not be able to edit them through the ACF UI.

If you choose JSON, you can import them again and edit them through ACF.

Method 2)

I prefer this method: create a folder called acf-json in your main theme folder. ACF will detect the folder and automatically save a copy of the fields as JSON files.

Whichever method you choose, make sure to add/commit any files created/changed to your repo.

Never used the Custom Post Type UI plugin, but I imagine it has a similar import/export capability.

Alternatively, you can also share an export of your DB, but there will be no version control for fields/etc.