Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared hosting Managed WordPress Cloud hosting VPS hosting By reader location Hosting finder
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Blog Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Developer · Guide

How to Use Git With WordPress

How to Use Git With WordPress

Short answer

To use Git with WordPress, track only the code you write, such as your custom theme and custom plugins, in a Git repository. Ignore WordPress core, uploads, wp-config.php, vendor, and the database with a .gitignore file. Commit in small steps on branches, push to a remote host, and deploy by pulling that code to staging first, then to the live server.

Key takeaways

  • Git records changes to files over time so you can recall and restore earlier versions.
  • Track only code you write; ignore core, uploads, wp-config.php, vendor, and the database.
  • A .gitignore file lists patterns to skip, and ! brings one path back inside an ignored folder.
  • Files already tracked stay tracked until you run git rm --cached on them.
  • Every Git clone holds the full history, so a fresh clone is a full backup of the code.

What does Git track on a WordPress site?

Git tracks the code you write, and it ignores the rest of the WordPress install.

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. Git Documentation gives that definition and notes that it lets you revert files, compare changes over time, and see who last changed something (checked November 2026).

For WordPress, that means your custom theme and your custom plugins belong in Git. Those are the files you edit, and they are the files you would want back after a bad change.

WordPress core does not belong in Git. Core files arrive with each WordPress update, and tracking them would fill your history with thousands of files you never wrote.

Media uploads do not belong in Git either. They are user content, they can grow to gigabytes, and a backup holds them far better than a repository does.

The database does not belong in Git at all. Git tracks files, while posts, pages, and settings live as rows in the database, so a backup is the tool that holds them.

What should you leave out of Git?

Leave out anything a tool can rebuild, anything that holds a secret, and anything that changes on every machine.

PathTrack in Git?Why
wp-content/themes/your-theme/YesCode you write
wp-content/plugins/your-plugin/YesCode you write
WordPress core (wp-admin/, wp-includes/)NoReinstalled with each update
Third-party plugins and themesNoManaged by the dashboard or Composer
wp-content/uploads/NoUser content, often very large
wp-config.phpNoHolds site secrets
vendor/, node_modules/NoRebuilt from a lock file
Cache, logs, and SQL dumpsNoMade fresh on each machine

wp-config.php holds secrets that must never reach a shared repository. Developer.WordPress.org states that NONCE_KEY and NONCE_SALT are defined in your wp-config.php file (checked November 2026).

Keep vendor out of Git too. GetComposer.org advises adding vendor to .gitignore, since you do not want all that third-party code in your versioned repository (checked November 2026).

Roots.io states that a Bedrock project keeps WordPress core and plugins out of version control, so the repository holds only custom code, settings, and the list of dependencies (checked November 2026).

What do you need before you start?

You need Git installed, a copy of your WordPress files, and a decision about what the repository will hold.

Install Git from your system package manager or from the installer on the Git site, then confirm it with git --version. That command prints the installed version, such as 2.x, and proves the tool is on your PATH.

Decide the scope first. The two common choices are one repository for a single theme or plugin, or one repository for the whole project minus core, uploads, and secrets.

A single theme repository is the simplest start. You work inside the theme folder, and nothing else in the install is touched.

A whole-project repository suits teams that deploy from Git. It holds the theme, the custom plugins, composer.json, composer.lock, and the settings files that are safe to share.

A guide on how to set up a staging site for WordPress shows where to check your Git-managed code before it reaches live visitors.

How do you start a repository for a theme or plugin?

Start the repository in the folder you want to track, add the files, and make a first commit with a clear message.

Open a terminal in the theme folder and run this command:

git init

That command creates a new Git repository in the folder. It adds a hidden .git folder that holds the full history from that point on.

Stage the files and commit them:

git add .
git commit -m "Initial commit for my theme"

The first command stages the files for the next commit, and the second records them with your message. Keep the message short and plain, so the history reads well later.

In a distributed system, each copy holds the full history. Git Documentation states that in a distributed system clients fully mirror the repository, including its full history, and that every clone is really a full backup of all the data (checked November 2026).

Connect the local repository to a remote host, such as GitHub, with git remote add origin, then push with git push -u origin main. The -u flag links the local branch to the remote one, so later pushes need only git push.

How do you write a .gitignore for WordPress?

Write a .gitignore file in the repository root that lists the paths Git must skip, then commit that file so the rules travel with the project.

A .gitignore file specifies intentionally untracked files that Git should ignore. Git Documentation states that each line in the file holds one pattern, and that files already tracked by Git are not affected by it (checked November 2026).

GitHub Docs states that you can create a .gitignore file in your repository root to tell Git which files and folders to ignore, and that you should commit the file to share the rules with others who clone the repository (checked November 2026).

A sensible file for a whole-project repository looks like this:

/wp-admin/
/wp-includes/
wp-config.php
wp-content/uploads/
wp-content/cache/
vendor/
node_modules/
*.log
*.sql

The leading slash pins a pattern to the repository root. A pattern with no slash, such as *.log, matches at any depth below the file.

Use ! to bring back one path inside an ignored folder. Git Documentation states that an optional ! prefix negates a pattern, so a matching file left out by an earlier pattern becomes included again (checked November 2026).

For example, these two lines ignore every plugin except the one you wrote:

wp-content/plugins/*
!wp-content/plugins/my-plugin/

The order matters here. The line that brings the plugin back must come after the broad ignore line, or Git never looks at that path again.

How do you make branches and commits?

Make a branch for each change, commit small steps with clear messages, and merge only when the branch works.

Create a branch for a new feature with this command:

git checkout -b fix-header-spacing

Work on that branch, then stage and commit in small steps. A commit that does one thing is easy to review, easy to revert, and easy to describe in one line.

Check what changed before you commit with git status and git diff. The first shows which files changed, and the second shows the exact lines.

Merge the branch back into main when the work is done and checked. Switch to main, run git merge fix-header-spacing, and push the result.

Delete a merged branch with git branch -d fix-header-spacing. Git Documentation states that -d deletes a branch, and that the branch must be fully merged in its upstream branch first (checked November 2026).

Use git branch -D only when you mean to drop unmerged work. Git Documentation states that -D is a shortcut for --delete and --force (checked November 2026).

How do you deploy with Git?

Deploy by pushing to a remote, then pulling or checking out that code on the server, or by letting an automated job do it for you.

The manual route is simple: push your branch, log in to the server, pull the latest code, and run composer install if the project uses Composer. The lock file then gives the server the exact versions you checked.

The automated route uses a workflow that runs on each push. A guide on how to deploy WordPress with GitHub Actions walks through that setup, from the workflow file to the server step.

Never deploy by pushing straight to the live folder without a check. A guide on how to set up a staging site for WordPress shows how to pull the same code to a staging copy first and check it there.

After a deploy, run git status on the server to confirm a clean state. If files show as changed on the server, someone edited live files, and those edits are not in Git.

Keep the database and uploads out of the deploy. Move content with a backup or a migration tool, not with Git, because Git cannot track database rows.

What mistakes should you avoid?

Avoid committing secrets, tracking files you meant to ignore, and working straight on the live branch.

Never commit wp-config.php, .env files, or API keys. Once a secret lands in Git history, deleting the file does not remove it from earlier commits, and the whole history must be rewritten.

If you already committed a file you meant to ignore, untrack it first. GitHub Docs states that to ignore a file already checked in, you must untrack it first with git rm --cached FILENAME (checked November 2026).

Git Documentation states the same fix: use git rm --cached to remove the file from the index, then add the name to .gitignore so it is not added again (checked November 2026).

Do not commit vendor, core, or uploads to make a deploy “easier”. The repository grows large, clones slow down, and updates become painful.

Do not work directly on main for risky changes. A branch keeps a broken edit away from the code that deploys, and it can be deleted with no harm done.

A guide on how to back up WordPress without a plugin covers the backup step that Git cannot replace, so your content stays safe while your code lives in Git.

How do you check that it worked?

Check the repository status, confirm the ignore rules hide what they should, and prove you can restore an older version.

Run git status in a clean repository. It should show a clean working tree, with no surprise files waiting to be added.

Run git status --ignored to list the files Git is skipping. Your uploads folder, wp-config.php, and vendor should appear there, not in the list of files to add.

Clone the repository into a fresh folder on another machine. The clone should hold your theme or plugin, composer.json, and composer.lock, and nothing else from the list you meant to skip.

A guide on how to test a WordPress backup covers the restore check for the content Git does not hold, so both halves of the site are proven.

Undo a bad change with git revert for a shared commit, or git checkout to bring back one file from the last commit. Both use the history Git recorded, which is the whole point of tracking the code.

Frequently asked questions

Does Git back up my posts and settings?

No. Git tracks files, and posts, pages, and settings live as rows in the database. Use a backup to hold the database and the uploads folder, and use Git only for theme and plugin code.

I already committed wp-config.php. How do I fix it?

First untrack it with git rm --cached, using the file name, then add the name to .gitignore and commit both steps. Adding the rule alone does not untrack a file Git already follows.

Should I track the whole WordPress install or just my theme?

Yes. Track the whole project minus core, uploads, secrets, and vendor, or track just one theme or plugin folder. The whole-project route suits teams that deploy from Git; the single-folder route is simpler for one theme.

Should I commit the vendor folder?

No. The vendor folder is rebuilt from composer.json and composer.lock on each machine, so it should stay in .gitignore. Commit the lock file instead, so every machine installs the same versions.

How do I delete a branch safely?

Use git branch -d with the branch name, which only works when the branch is fully merged. Use git branch -D only when you mean to drop work that was never merged.

How do I check my repository is set up right?

Check git status for a clean tree, run git status --ignored to confirm uploads, wp-config.php, and vendor are skipped, and clone the repository into a fresh folder to prove it holds only what you meant to track.

Sources

  1. About Version Control Git
  2. gitignore Documentation Git
  3. Ignoring files GitHub Docs
  4. Bedrock: WordPress with Composer and Git Roots
  5. Basic usage Composer
  6. Nonces WordPress Developer Resources

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

Written and checked byWPLegible Editorial Team Independent WordPress reviews and guides

Researched from the primary sources listed above and checked against our editorial rules before publishing.