Amit
Amit

Reputation: 7838

Using git to track changes made on the server without commit

Before I ask my question, I want to mention that I am only today starting to experiment with git, which therefore makes me a total git newbie.

I frequently work with graphic designers on Wordpress websites for clients. After I upload the code to the server, the graphic designer sometimes edits the CSS & other files directly on the server using the Wordpress editor (within the Wordpress Admin panel).

You can imagine that this causes a problem for me, because I then have to first re-download all of the modified files to my local development folder -- and since I don't know which files were edited, I have to re-download the entire theme folder. Then I make the changes locally, and re-upload to the server.

From what I read online, it seems Git could make this a lot less painful.

My question: If the designer makes changes to files on the server using the wp editor without using git / commit, would using Git still help me? Would it download all of the modified files to my machine automatically, in a similar way that Dropbox works?

Upvotes: 0

Views: 927

Answers (1)

Roscius
Roscius

Reputation: 1534

Doing a git pull to move the files, wouldn't collect any changes from the working directory on the server. A potential workflow might be to first log in to the server and commit all of the changes and push them to a bare repository. You could then pull from the bare repository locally and see the changes that others have made and git will help you to merge them in to your local environment.

You could also deploy from your local environment to production in the same way, by pushing to the bare repository and then pulling from the bare repository to the production server.

The bare repo seems like an extra step, but both of your environments (the server and your local) are working environments, so transiting the bare repo will make it a little easier on you with committing and merging. (If I'm off track on this one, I'm sure someone will point out the errors in my ways....)

You'll want to exclude the wp-config.php file from the repo, or modify the permissions site up based on environment variables or the like (ie set an environment variable in your vhost file locally and on the server and use a conditional statement to determine which DB credentials to use in wp-config.php). Something like:

switch ($_SERVER['APPLICATION_ENV']) {
case 'local':
    define('DB_NAME', 'local');
    define('DB_USER', 'localuser');
    define('DB_PASSWORD', 'localpwd');
    define('DB_HOST', 'localhost');
    define('WP_HOME','http://local.verycoolwebsite.com');
    define('WP_SITEURL','http://local.verycoolwebsite.com');
    define('WP_DEBUG', true);
    define('SAVEQUERIES', true);
break;

case 'production':
    define('DB_NAME', 'production');
    define('DB_USER', 'www');
    define('DB_PASSWORD', 'foobar');
    define('DB_HOST', 'localhost');
    define('WP_HOME','http://www.verycoolwebsite.com');
    define('WP_SITEURL','http://www.verycoolwebsite.com');
    define('WP_DEBUG', false);
    define('SAVEQUERIES', false);
break;
}

It's also probably a good idea to exclude image directories if they are large and don't need version control.

As another option, take a look at the rsync command if what you are looking for is moving changes as opposed to full version control.

Upvotes: 1

Related Questions