[conspire] A Git Tip

Deirdre Saoirse Moen deirdre at deirdre.net
Sun Mar 1 05:35:20 PST 2015


Scott DuBois asked me about my git repositories at last night’s Cabal.

And we talked about cron.

Most of what I’m working on is in private repositories. Now, a lot of people know you can have as many public repositories as you want on GitHub—but you have to pay for private repos. Sad panda.

However, bitbucket.org offers as many *private* repositories as you want. For free. Sure, you can have git locally, but it’s almost no extra effort to set up a remote push so you can also have offsite backup.

Then Ross and I were talking about WordPress, so here are my tips about for setting up a git repository for WordPress:

1. Grab this .gitignore file: http://cdn.wpengine.com/wp-content/uploads/2013/10/recommended-gitignore-no-wp.txt

2. Save it as .gitignore in your WordPress director(y|ies).

3. Then:

git init
git add .gitignore
git commit -m “Adding .gitignore”
vi .htaccess
git add .htaccess
git commit -m “Adding .htacess”
git add wp-content
git commit -m “Initial add of wp-content”

That’s usually the point where I create the bitbucket repo and set up pushing.

By default, .htaccess doesn’t exist on WordPress installs, and permalinks (nice URLs) break without it, so it’s kind of important to have. Here’s the .htaccess I use:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

git remote add origin git at bitbucket.org:(username)/(reponame).git
git push -u origin master

4. My crontab (applicable even for non-WordPress, y’know)

$ crontab -l
5 */6 * * * /Users/deirdre/bin/backup-work.sh

(so four times a day at five minutes past the hours divisible by six)

5. That’s a braindead (hey, it works!) little shell script that has things like this:

echo -e "\n* Git Update: deirdre.net...\n"
cd /Users/deirdre/Sites/deirdre.net
git add *
git add .htaccess
git commit -m "Automatic checkin."
git push -u origin master

et voila.

Deirdre





More information about the conspire mailing list