GitHub’s free alternatives

Personally, I love GitHub.  And I try to promote it as much as I can, and I’ve even got a few organizations setup their repositories there.  However, I am still asked once in a while for a good alternative.  These work either for people who don’t have the money to pay for GitHub’s private repositories, or who are required to keep their code in-house.

Here are a few alternatives to the GitHub hosting service. There are two types of software: locally installed software and hosted.  These are decent for smaller companies that don’t have the budget for licensing a hosted service.

Free Local Install

  • gitlabhq.com – this project looks really good, with new releases every month.
  • gitorious – solid, free alternative to GitHub.

Free Hosted

  • gitorious.org –  open source projects are free, like github.
  • bitbucket – unlimited free private repositories for up to 5 users. The pricing model is similar to the other Atlassian products.

Also, have a look at Sourcegraph, which you can host yourself or pay for a hosted service.

wp-config.php and git

If you are storing your WordPress changes in git and then deploy the project between different machines (local, test server, production environment, etc), then you are probably familiar with a problem of wp-config.php file.  WordPress uses it for things like database credentials, which vary from machine to machine.  But you can’t just ignore the file since it’s plays the role in WordPress bootstrap.  The solution that we are using at work is very simple: have an additional configuration file, such as wp-config-local.php, which defines local settings, and which is ignored from git.

Here is how to do this.  First, you need to create the file itself.  Let’s say we want to change the database credentials which WordPress should use on the current machine.  Create a file wp-config-local.php with the following content:

<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'localdev');
define('DB_PASSWORD', 'code15poetry');
define('DB_NAME', 'wp_playground');
?>

Now we need to include the file from the wp-config.php. The local configuration file should be optional, so we only use it on those machines that need it. Here is the code that I’ve added to the top of my wp-config.php:

// Load wp-config-local.php
$localConfig = dirname(__FILE__) 
    . DIRECTORY_SEPARATOR . 'wp-config-local.php';
if (file_exists($localConfig) && is_file($localConfig) 
    && is_readable($localConfig)) {
    require_once $localConfig;
}

If you will have a look at your WordPress website now, it’ll probably be broken. That’s because you are not allowed to redefine constants. We’ve defined that in our wp-config-local.php which loads first, and then they are defined in the wp-config.php as well. We should work around this. For any constant that is defined in wp-config.php and which you want to be able to set from wp-config-local.php, change the line in wp-config.php like so:

// before
// define('DB_USER', 'root');
// after
if (!defined('DB_USER')) { define('DB_USER', 'root'); }

With this, you’ll basically have values in wp-config.php act as defaults. If there is no local configuration, they will be used. Otherwise, the local ones will be utilized.

The last tiny bit that you need to do is add wp-config-local.php to your .gitignore file. That’s it. Now commit, push, and enjoy.

Stash – privately hosted Git repositories

As far as I am concerned, GitHub is the king and queen of applications in the git world.  But it has a downside that is not easy to work around: GitHub Enterprise is expensive.  Keeping code on GitHub infrastructure is not always allowed by authorities and such, and then things get really expensive.  That’s where, I think, Stash can come in.

Stash is a product of Atlassian, the same company that owns Jira, BitBucket, and a few other well-known developer tools.  Given that Stash has only been launched this year, and judging by the screenshots, GitHub probably provides more functionality.  But as I said earlier, GitHub’s price might be simply too high for some companies.

It’s also worth noting that both companies have recently received large investments (Atlassian got $60 million and GitHub got $100 million).  Since private repositories and in-house installations seem to be the primary source of income for both of them, I’m seeing a revved up competition between the two in the nearest future.