How to use WordPress with Git efficiently

I use to work with frameworks like Symfony, Angular, Laravel and more.

When it comes to VCS (Version Control System), we need to remind some facts.

WHAT ARE THE ADVANTAGES OF VCS
1. Keep track of changes by owners, time…
2. Easily roll back changes when necessary
3. Easier to collaborate with other developers

WHAT IS NOT VCS MADE FOR
1. Replacement for scheduled backups, VCS !== BACKUP !!!
2. Debugging. Since every little change is tracked, it’s not its purpose.
3. Committing untested or broken code to the repository… Just a matter of sense !
4. Committing generated content (from user or otherwise)
5. Uploads & thumbnails => heavy repo with absolutely no benefit, use a cdn for media content !

WHAT IS THE GOAL OF VCS WITH WORDPRESS (Like another framework or cms)
1. Keep sensitive information out of the repository
2. Avoid wordpress core and upload files

Ok. You will surely tell me that this way, it will be a pain to retrieve the full project for a new developer, because there will be no wordpress core files, nor wp-config.php file.

Sure you’re right. But remember, VCS !== BACKUP, keep third parties you are not allowed to touch apart of your repository.
ANND, I will show an easier way to bypass this simple issue.

  • It is not a good way to modify wordpress core (what about future updates)? Don’t keep core files inside your repository.
  • Config file is personal to each user, never shared it on vcs, keep database datas secret.

NOW, LET’S START !!!!

Let’s start with the .gitignore file content

# Ignore everything in the root except the "wp-content" directory.
/*
!.gitignore
!wp-content/
!.htaccess

# Ignore everything in the "wp-content" directory, except the based themes and the "tmp" directory.
wp-content/themes/twenty*
wp-content/tmp/

#Do this essentially if you store your media content inside a cdn
wp-content/uploads/ 

# Hidden files
*.DS_Store
*Thumbs.db
*.sass-cache*
*~imageoptim*

Now, let’s grab the wordpress core and config files. For that we will need “wp-cli” extension, you can download it here: https://www.howtoforge.com/tutorial/getting-started-with-wp-cli/

Once, you have “wp-cli” enabled in your cli environment, we can start the fun:

  1. Install WordPress core files with a specific version
    wp core download --version=x.x.x --allow-root
    
  2. Install config file with database datas

    wp core config --dbname=mysite --dbuser=root --dbpass=password --dbhost=127.0.0.1
    

And here we go, quite simple, enjoy 🙂

How to use WordPress with Git efficiently

Git issue with WordPress some folders are ignored

Hi everyone,

It’s been a while I didn’t wrote here and I’m glad to see that I make more and more visits, thank you.
It feels good to be back and share with you my issues.

So today I faced a strange problem with WordPress.

Our wordpress project uses Retouch theme with Unyson plugins.

After some updates on the project, I created a git repository and put my changes in, inside a branch.
Everything was ok, expected that if you pull the git repository, even if you re-upload the database, it seems that instead of displaying the normal content from the database, it was a hash that was shown, something like “{length: xxx, hash: xxx}”.

After many hours, I noticed that the problem was a plugin issue with Unyson Builder extension that was missing in my repository.

I can’t actually figure why, but in BitBucket when I access this directory “wp-content/plugins/unyson/framework/extensions/shortcodes/”, the next folder seems to be two folders attached like this “extensions/page-builder”.

So git was ignoring this folder no matter what I could do.

To solve this kind of problem, you always have to check that git doesn’t ignore accidentally some folders. After your “git add” and before any “git commit”, use this command:

git status --ignored

Thank you for reading me.

Git issue with WordPress some folders are ignored