GIT and Development URL's point to production

I am experimenting with GIT for version control. I have a production environment that I created a repo for HERE, then did a git clone locally. I created/modified the wp-config to work with my local DB. The index page loads, but all of the links for any pages or post point to the production URLs.

How can I make this so running the local instance allows me to browse to all the local pages/posts?

Topic github git Wordpress

Category Web


Besides doing the find and replace on the domain as saved in the site's database, you'll also want to either:

  • ignore and remove the wp-config.php file from your git repo (so that the local development instance database connection info doesn't keep overwriting the server's and vice versa), or
  • add some environment specific configuration (can be a conditional statement in the wp-config, but better yet- should be a call to check for the existence of and use an external database config file whose name matches the environment)

My preferred method is to use WP CLI's search-replace command to swap out domains in my local site. If I have example.com on my live site, I'll use example.local on my local install, so the command to fix URLs on the dev site would be:

wp search-replace example.com example.local

I would use WP DB Migrate to export the DB in the production environment. It allows you to rewrite URLs. Then you import that in your local DB.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.