Uncommon situations

Last updated on
24 September 2020

The sections on this page (see "On this page" in the sidebar) are each independent, and describe how to deal with situations that you may see as a project maintainer, but that are somewhat uncommon.

Move files from one Git project to another, with history

This is useful if you have a large project and decide to spin off one of the sub-modules to another project. See these posts from: Stack Overflow, Greg Bayer, Sven Decabooter. Here are the steps:

  1. Clone all of the branches of your original project into separate directories (find the clone URL on the Version Control tab of your project):
  2. git clone --branch 5.x-1.x CLONE_URL oldproject5
    git clone --branch 6.x-1.x CLONE_URL oldproject6
    ...
  3. In each cloned directory, remove the connection to the original repo, and filter to contain only the files you want (repeat for each branch clone):
    cd oldproject5
    git remote rm origin
    git filter-branch --subdirectory-filter SUBDIR_TO_KEEP -- --all
  4. Clone the repo for the new project as maintainer (see the Version Control tab for that project).
  5. From the new project's repo, add the old projects as remotes, fetch their data, and remove them as remotes (repeat for each branch clone):
    git remote add oldproject5 ../oldproject5
    git fetch oldproject5
    git remote rm oldproject5
  6. Remove any tags from the new project that don't apply and push that change to the repo. Create new branches and push them to the repo. See Creating a project release for details.

Rename a project, preserving history

  1. Create the new project on drupal.org.
  2. Note the clone URLs for the old and new projects from the Version Control tabs on each project.
  3. Clone the old project with a --recursive flag: git clone --recursive --branch FIRST_BRANCH OLD_CLONE_URL
  4. In the old project, add a remote to the new project: git remote add NEWPROJECT NEW_CLONE_URL
  5. Push the current code to the new project: git push NEWPROJECT FIRST_BRANCH
  6. Repeat steps 3-5 for each branch.
  7. Make sure to update the Maintainers list on the new project to match the old project's maintainers so that you'll see the commits in the sidebar.

Copy your repository onto Drupal.org from an existing repository

These are one-time steps for populating a Drupal.org repository from an existing Git repository (such as Github or anywhere else it might live).

# Clone the repo as a mirror from the original source
git clone --mirror [github_or_other_url]
cd [repository]
# Create a new remote using the maintainer URL from the version control tab.
git remote add newproject [maintainer_url_from_git_instructions]
# Push all the code and branches into the git.drupal.org remote
git push --all newproject

Deal with a "forced update" message

If you attempt to rebase a branch you've already pushed, or change a commit you've already pushed, you may see an error like this when you attempt to git fetch or git pull:

+ 2b40273...6488b40 8.x-1.x    -> origin/8.x-1.x  (forced update)

You have basically two options to fix this:

  • Discard the changes on your local repository: git reset --hard origin/8.x-1.x
  • Rebase your local repository: git rebase origin/8.x-1.x (see the Rerolling patches page for how to deal with any resulting merge errors).

Tags

Help improve this page

Page status: No known problems

You can: