Cloning a Module's project Git repository

Last updated on
20 July 2022

For drupal core patching go here.

Getting a local copy of a Git repository is known as "cloning" the repository. This page explains how to do it for Git repositories in the Drupal project. Background information:

Using Git to clone a Drupal repository

  1. Go to the project page, such as: http://drupal.org/project/colorbox/
  2. Click the Version Control tab. This will take you to a page like http://drupal.org/project/colorbox/git-instructions
  3. Select the branch that you want to clone (you can always switch branches later).
  4. Click the Show button to update the clone command.
  5. Copy the command shown under Setting up repository for the first time. Example:
    git clone --branch 8.1.x http://git.drupal.org/project/colorbox.git
  6. Open a terminal window and change to the directory above where you want the cloned source code to be located. For example, you might want to put a module in a working Drupal site under web/modules/contrib.
  7. Paste or type the clone command in your terminal window. A new subdirectory will be created, such as colorbox in this case. The clone command will fail if a subdirectory with this name already exists.
  8. Change to this directory, and you are ready to view or work on the source code.

Switching a repository to being a maintainer

If you are or become a maintainer of a project hosted on Drupal.org, and you follow the first two steps in the Git cloning section above, you will see that the Version Control page will have a slightly different clone URL:

git clone --branch 8.1.x git@git.drupal.org:project/colorbox.git

If you originally cloned a repository as a non-maintainer, and then later became a maintainer, you will need to update your repository to use the new clone URL, in order to be able to push your changes back to the source code repository on drupal.org. To do this, you have two choices:

  • If you do not have any local changes that you need to preserve, you can delete the directory and re-clone using the clone command with the maintainer URL.
  • If you have local changes that you want to preserve, you can open a terminal window, change to the repository directory, and run the following command:
    git remote set-url origin git@git.drupal.org:project/colorbox.git

Updating the source (possibly to a new branch)

To pull in the latest changes from a git repository:

  1. Make sure you don't have any local, uncommitted changes (git status will tell you; git checkout will clean them up).
  2. Use the git pull command to pull the latest changes from the repository.
  3. Use the git checkout newbranchname command to check out the latest development branch, if you are not already using that branch.

Getting source code using Composer

Some modules use Composer to manage their dependencies. For these modules, it may be easier to use Composer to get the module's source code rather than Git, although you will not be getting the Git repository:

composer require drupal/colorbox:1.x-dev --prefer-source

Tags

Help improve this page

Page status: No known problems

You can: