Question: I have just copied a directory to another local git repo. It turns out that directory I copied is also another git repo, so now I have what I assume is called a nested repo.

I wanted to keep the outer repo and then to integrate the inner repo as the outer repo (modifying the remote origin, per say). One of my concern is because the inner repo has several branches. There is only one branch among them that I wanted to keep.

I am quite confused with what's the best practice to solve this issue. Hope someone can give me some pointers for this. Thanks!

Answer: 
You can only keep the files, not the history.

* checkout the desired branch at that other location.
* copy the other repo into the target repo.
* delete `.git` folder and any `.git*` file from the destination folder.
* checkin the new folder into the target repo

In the `git shell` do this:

```
/other/location/otherPrepo>git checkout the-branch-wanted
/other/location/otherPrepo>cp -R  * -R /target/location/targetRepo/targetFolder/
/other/location/otherPrepo>rm -rf /target/location/targetRepo/targetFolder/.git*
/other/location/otherPrepo>cd  /target/location/targetRepo/
/target/location/targetRepo/>git add  targetFolder
/target/location/targetRepo/>git commit -m "added files from otherPrepo"

```

[edit:] don't forget the checkin...
You can use `git subtree` to import files from a second repository while keeping their history.

1. Start from a clean working tree (check with `git status`). If you've already tried to manually copy files in, delete them. Git will copy them for you.
2. `cd` to the top level of your repository.
3. Run `git subtree add --prefix=inner path/to/other/repo some-branch`. This creates an `inner` subdirectory and puts the contents of the other repo's `some-branch` in it.
4. Observe that `git log` shows the history of the imported files.