Skip to content

Instantly share code, notes, and snippets.

@djdefi
Last active April 19, 2022 13:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djdefi/8cbaa0252d8a1838a82ec464e2c697d1 to your computer and use it in GitHub Desktop.
Save djdefi/8cbaa0252d8a1838a82ec464e2c697d1 to your computer and use it in GitHub Desktop.
Wordpress change tracking with Git
# Keep these files out of the repo
/wp-content/themes/twenty*
/wp-content/upgrade
/wp-content/uploads
/sitemap.*
/wp-config.php
*.sql
# Hidden files
*.DS_Store
*Thumbs.db
*.sass-cache*
*~imageoptim*
RedirectMatch 404 /\.git

Howto

  1. Change directory Wordpress root directory (on local system or remote server).
  2. Add .htaccess and .gitignore files.
  3. Run git init on the Wordpress directory.
  4. Run git add --all
  5. Run git commit -am "Initial Commit"
  6. Change some files.
  7. If on remote server, run git status - If local, sync with remote FTP first.
  8. Commit new changes with git commit -am "Commit message".

If you wish to track the project on GitHub.com, please follow the official guide on adding an existing project to GitHub. Using a private repository is reccomended, to keep any sensitive files or information secret.

Additional commands for checking on changes.

git ls-files -dmo --exclude-standard

Will return empty if there are unchanged files.

git diff

Shows differences between changed file versions.

FAQ

Q: What is the .htaccess file for?

A: Prevents the hidden .git directory from being served by the webserver. This directory can contain internal details or Git passwords, so we don't want open to the public.

Q: What is the .gitignore file for?

A: Generated content (user- or otherwise) should not be tracked, however this may vary depending on your use case. You may want to track the /wp-config.php for changes also, which can be achieved by removing that line from the .gitignore file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment