git: how to merge commits from a remote to a different path?

I have a git repository with remote foo.

foo is a web app, is contains some files and dirs directly in its root:

  • How to delete everything inside GIT repository?
  • How can I push specific commit to a remote, without the previous commits?
  • How can I use git as the scm provider in sonarqube 5.0 ( using sonar-runner )
  • How to tell which branch a github commit was for?
  • How to configure an existing git repo to be shared by a UNIX group
  • How to use libgit2sharp to create a new branch from local to remote?
  • Rakefile

    My main git repository is a larger system which comprises this web app. I want to pull the commits from foo, but I need the files to reside inside the web dir. So they should become web/app, web/public, etc.

    I don’t want to use foo as a submodule. I want to merge foo into the main repository and then get rid of it.

  • Mercurial linear history using hg rebase with uncommited changes
  • Can I specify in .git/config to fetch multiple refspecs?
  • Git Error; RPC failed; result=22, HTTP code = 401
  • Should diff3 be default conflictstyle on git?
  • Git post-receive hook doesn't remove deleted files from master
  • Why is git not ignoring .dcu files?
  • 3 Solutions collect form web for “git: how to merge commits from a remote to a different path?”

    Here’s a community-wiki version of your answer if you’d like to accept it as the answer.

    This answers my question:

    The up-to-date resources for subtree merging are:

    • Git Book chapter6.7
    • How to use the subtree merge strategy
    • GitHub article “Working with subtree merge”

    Cite from How to use the subtree merge strategy:

    In this example, let’s say you have the repository at /path/to/B (but it can be an URL as well, if you want).
    You want to merge the master branch of that repository to the dir-B subdirectory in your current branch.

    Here is the command sequence you need:

    $ git remote add -f Bproject /path/to/B
    $ git merge -s ours --no-commit Bproject/master
    $ git read-tree --prefix=dir-B/ -u Bproject/master
    $ git commit -m "Merge B project as our subdirectory"
    $ git pull -s subtree Bproject master

    See also for comments the article “Subtree merging and you”.

    Git Baby is a git and github fan, let's start git clone.