Git

Backdrop CMS configuration files and Git: The versioned staging approach

There are lots of different approaches to managing Backdrop CMS configuration files in Git, but this one is my favorite. It works great for projects with multiple developers, and it can also be easily adapted for multiple deployment environments, as on Pantheon.

This versioned staging directory strategy has been adapted from a recommendation from @populist and @davidstrauss based on how the config directory is being managed for Drupal 8/9/10 on Pantheon.

How to add back the Git history, when you forgot to clone

When porting modules from Drupal 7 to Backdrop CMS, it's natural for people to download the Drupal project as usual, and then start to make changes to the code so it will work for Backdrop. When they have got a working Backdrop version of the module, they are often inclined to contribute it back to the Backdrop community -- which is great!

One of the three minor requirements for a ported Drupal project to be included in the Backdrop contrib-group is that the Git history be included from the Drupal project.

The most important reason we want to keep the history is because we want all the Drupal contributors to get credit for all the hard work they have done on the project. Keeping the history can also make it easier to cross-port fixes from the Drupal project, or even maintain both projects at the same time.

Git remotes - Connecting your local site to a remote repository

Working with Git is great, but before you see the real benefits of using Git you'll need to have your project hooked up to a remote repository.

Most people enter the world of Git when they are brought on to a project with multiple developers. In this case, there is likely already an existing repo, and all you need to learn to do is pull the latest changes, and push your own.

Navigating to your code in the terminal

First, you'll need to get a local site up and running. You can do so using MAMP, Kalabox, or any other tool that makes that easier, but make sure you can find out where the files are saved on disk. You'll need to get there from the command line to follow along with the rest of this post.

Open your terminal, and navigate to this location. I do this using the cd command. cd stands for "change directory".

Git

Git Basics - getting started on the command line

Tools like Git desktop and Acquia dev desktop allow people to use Git without understanding how it actually works. These tools are a fantastic on-ramp to the world of Git, but at some point I hope that everyone gets a chance to work with Git directly from the command line. This will complete your understanding of what happens when you push those buttons in the desktop applications, and make you better at using both! Here are some basics to get started.

Navigating to your code in the terminal

First, you'll need to get a local site up and running. You can do so using MAMP, Kalabox, or any other tool that makes that easier, but make sure you can find out where the files are saved on disk. You'll need to get there from the command line to follow along with the rest of this post.

Open your terminal, and navigate to this location. I do this using the cd command. cd stands for "change directory".

Git

Backdrop CMS configuration files and Git: The figure-8 approach

I've written about how to manage your configuration directory in version control (Git) several times, but now that I've done it in the wild on a few different sites, I thought I'd write it up here as well.

Note: this figure-8 approach works best when there is only a single developer on the project. If there is more than one, this approach can get confusing, and I prefer the versioned staging directory approach.

Below I have outlined how I set up most of my sites, with the Git root a directory above the webroot. This allows me to keep things that should not be web-accessible (like config!) in version control.

Keeping your Drupal site up to date with Git and Drush

I don't recommend trying to stay 100% on top of all updates for all of your modules all the time. However, when a security update becomes available for one of your modules, you should certainly make that update as soon as is reasonable. And while you're at it, that might be a good time to bring everything else up to date as well. Below is my recipe for keeping modules on my Drupal sites up to date, by using two of my favorite development tools, Git and Drush.

© 2024 Jeneration Web Development