Files relocation

git format-patch

This section is based on OCA’s instruction.

Used variabes:

  • $REPO_PATH, $REPO_NAME - source repository
  • $MODULE - the name of the module you want to move
  • $BRANCH - the branch of the $REPO with $MODULE
  • $DEST_REPO_PATH, $DEST_REPO_NAME - target repository
# Set variables
export REPO_PATH=/path/to/misc-addons REPO_NAME=misc-addons MODULE=some_module BRANCH=10.0 DEST_REPO_PATH=/path/to/mail-addons DEST_REPO_NAME=mail-addons

# Create patch
git fetch upstream
git format-patch --stdout --root upstream/$BRANCH -- $MODULE > /tmp/relocation.patch

# Remove module from source repository
git checkout -b $BRANCH-$MODULE-relocation-remove upstream/$BRANCH
git rm -r $MODULE
git commit -m "[REM] $MODULE is relocated to $DEST_REPO_NAME"
git push origin
# then create PR on github

# Add commits to target repository
git fetch upstream
git checkout -b $BRANCH-$MODULE-relocation-add upstream/$BRANCH
git am -3 < /tmp/relocation.patch
git push origin
# then create PR on github

git filter-branch

This section is based on

  • Move directory 1 from Git repository A to Git repository B.
  • Git repository A contains other directories that we don’t want to move.
  • We’d like to perserve the Git commit history for the directory we are moving.
Let’s start
  • $REPO: the repository hosting the module (e.g. misc-addons)
  • $DEST_REPO: the repository you want to move the module to (e.g. access-addons)
  • $MODULE: the name of the module you want to move (e.g. group_menu_no_access)
  • $BRANCH: the branch of the $REPO with $MODULE (source branch, e.g. 8.0)


If you have installed git from official ubuntu 14.04 deb repository then you should first update it. You can update git using this instruction Update git

$ cd ~
$ git clone$REPO -b $BRANCH
$ cd $REPO
$ git remote rm origin
$ git filter-branch --subdirectory-filter $MODULE -- --all
$ mkdir $MODULE
$ mv * $MODULE # never mind the "mv: cannot move..." warning message
$ git add .
$ git commit -m "[MOV] $MODULE: ready"
$ cd ~
$ git remote add $MODULE-hosting-remote ~/$REPO
$ git pull $MODULE-hosting-remote $BRANCH

After the last command you will have the module with all its commits in your destination repo. Now you can push it on github etc. You can remove ~/$REPO folder - no use of it now.


Cloning - this is required step. It is temporary directory. It will removed all modules except the one that you want to move.

The following script may come in handy if you need to move several modules. But be sure that you understand all its commands before using.


echo $source_repo

if [ -n "$1" ]
       echo $module
       echo "Must be module name"
       exit $E_WRONGARGS

if [ -n "$2" ]
       echo $dest_repo
       echo "Must be dest_repo"
       exit $E_WRONGARGS

if [ -n "$3" ]
       echo $branch
       echo "Must be branch specified"
       exit $E_WRONGARGS

cp -r $source_repo ../$module
cd ../$module
git remote rm origin
git filter-branch --subdirectory-filter $module -- --all
mkdir $module
mv * $module
git add .
git commit -m "[MOV] module -- $module"
cd $dest_repo
git remote add repo_moved_module $source_repo/../$module
git pull repo_moved_module $branch --no-edit
git remote rm repo_moved_module
rm -rf $source_repo/../$module

In order to use it you should make the file in your home directory and put all lines above there and make this file executable.

$ cd ~
$ chmod +x

To do the moving of group_menu_no_access from addons-yelizariev to access-addons with the take the following steps.

$ cd ~
$ git clone
$ cd addons-yelizariev

This part is the same as moving without the script. But then I type only one command instead of many in case of fully manual approach.

addons-yelizarie$ ~/ group_menu_no_access ~/access-addons 8.0