user1801669
user1801669

Reputation: 163

merge a branch into a new sub directory on the master

I have a repo with master and feature branch. I would like to know if there is a way to merge the feature branch as a new sub directory under the master branch.

Thanks!

Upvotes: 3

Views: 719

Answers (2)

mgarciaisaia
mgarciaisaia

Reputation: 15540

git am has a --directory=<dir> switch, so you tell which directory to use as the base of the applying patches.

So, first make a git format-patch and then apply them:

$ git checkout master
$ git format-patch -o ../patches/ master..feature-branch
$ git am --directory=feature-subdir ../patches/*

--directory=<dir> is passed to git apply by git am. From git help apply:

   --directory=<root>
       Prepend <root> to all filenames. If a "-p" argument was also passed, it is applied before prepending the new root.

       For example, a patch that talks about updating a/git-gui.sh to b/git-gui.sh can be applied to the file in the working tree modules/git-gui/git-gui.sh by running git apply
       --directory=modules/git-gui.

Upvotes: 3

Samy Dindane
Samy Dindane

Reputation: 18706

Yes you can. Simply move the content of the feature branch to a directory, then merge it with master.

Upvotes: 0

Related Questions