Support

Account

Home Forums ACF PRO Working with git/branches/acf json

Solving

Working with git/branches/acf json

  • I have something which puzzles me for a while reg. working with (git) branches.

    Like any decent development company we work with git ๐Ÿ˜‰

    I have a branch named X, which is branched of the master branch.
    I add fields to a certain group.
    When I’m finished I commit my work.

    It doesn’t get deployed/merged immediately because of code checks (by colleagues) etc.

    If I then branch again from master, these fields are (still) in the database.
    If I then add another field to the same group as where I’ve added something in the previous commit, these fields in the db also get saved to the JSON file.

    How can we prevent this ?

    Is it possible to ALWAYS read the JSON files and never from the database ? IMO that would be the solution since no other fields, get ‘loaded’ into the branch you’re working in.

    If this is possible, I am not aware it is ๐Ÿ™‚

  • This may not be for you. I have one site where there can be several changes going on at the same time by different developers. I also use git. To manage this I have multiple dev/staging/testing sites. A specific change is only done on one of these sites. In your case, each branch would equal another dev site, reusing dev sites for different purposes as branches are merged. There was a lot I needed to learn about .gitignore to accomplish this. Basically, in my case, the root of git is the root of the site and I ignore all of the WP files and anything else that will be updated through the normal update process while any file on the server that could might need changing is part of the repo. I needed to do this to include custom PHP files in folders off the root as well as include the theme and specific custom plugins for WP. It’s really complicated, but the only way I could figure out how to accomplish letting multiple devs work on different changes and only pushing specific changes to the live site.

  • I can see the logic behind this, but I think this is ‘too much’ for me.

    Do you know if what I describe, can be realised ? Basically read from json only instead of from DB, because I think that would ‘solve’ the issue.

    Do you agree ?

  • I think that the only way you could do this would be to delete and re-import the field groups each time.

    ACF does only read from the JSON if it exists, but not when editing a field group. In this case it only reads from the database. But ACF will write to the JSON files when you update including all fields that are in the database for the group. I don’t know that there is any way to prevent ACF from doing this or doing what you want.

    So basically
    1) Create Branch
    2) Delete all of the field groups, maybe just the ones changed in some other branch)
    3) Import the effected field groups, You can import them directly from the ACF JSON folder. Also, I think, but I’m not sure, that field groups that are in the acf-json folder but do not exist in the database may be available for sync.

  • Apart from whether it’s going to happen or not…
    Do you agree this would be solved probably if all (field) data would come from the json file ?

  • I don’t really know. I guess, maybe. It makes sense if you can force ACF to load the field group edit page from the JSON file.

  • I think I have it working now.
    If I start a new branch, I first branch from master.
    Delete all groups.
    Commit it.
    Then delete the branch.
    Then re-branch from master.
    Sync all groups.
    Do my stuff.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.