Keeping code on GitHub and Drupal.org

Posted on 22/08/2016

Drupal.org encourages developers to host all of their Drupal-related Open Source code directly on Drupal.org. This is great, because all your OS code will be associated with your account and you will get a lot of extra features such as issue tracking, release publishing, ability to reference other issues and so on. However, current interface of DrupalCore.org website is not the most user friendly, especially when you want to have a quick look at the code of a contrib module.

This is why I think developers should host mirror repositories on another service where the source code can easily be checked through the browser. Why would anyone want to do this? Well, there are dozens of modules that revolve around using one simple hook to achieve certain functionality for example. If you are developing your module, you might want just to check how was that hook used in the contrib module, so you can adjust the code for your project.

To set this up, you will need 2 remote destinations: one on GitHub (or Gitlab, BitBucket, etc.) and the second one on Drupal.org. To keep things simple and self-explanatory, I suggest naming them just like that - github and drupal.

Here's how to set proper destinations:

  1. # Add GitHub source.
  2. git remote add github https://YOUR_USERNAME@github.com/YOUR_USERNAME/YOUR_REPO.git
  3. # Add Drupal.org source for a full project.
  4. git remote add drupal YOUR_GIT_USERNAME@git.drupal.org:project/YOUR_PROJECT.git
  5. # OR Add Drupal.org source for a sandbox project.
  6. git remote add drupal YOUR_GIT_USERNAME@git.drupal.org:sandbox/YOUR_GIT_USERNAME/PROJECT_NODE_ID.git

Do note that your git username on Drupal.org can be different than the one you use for logging in to Drupal.org. You can check your username by logging to Drupal.org, going to your profile page and then going to "Edit" -> "Git access".

Now when you want to push the code, here's what you need to do;

  1. # Push the code on GitHub.
  2. git push github
  3. # Push the code on Drupal.org.
  4. git push drupal

If for whatever reason you want to push one branch into another (e.g. local master to 8.x-1.x on Drupal.org), here's how to do that:

  1. git push drupal master:8.x-1.x

That's it!

Last thing: do bear in mind that contributions by other members are easier to track through issues on Drupal.org. If your project is used by others as well, use Drupal.org issue tracking system to be fair to contributors.