1

Current repo looks like this...

/ab/docter
/ab/pepper
/cd/..
...

I want to keep the whole history in ab and move it to a new Repo in GitHub.

/doctor
/pepper

I tried to pull and manually move it to ab repo but the history doesn't come with the push. :(

merry-go-round
  • 4,533
  • 10
  • 54
  • 102
  • What if you move all the files, commit that changes on a new branch and then rebase onto your master branch? – KeukenkastjeXYZ Apr 22 '19 at 18:44
  • @KeukenkastjeXYZ that sounds like a plan... Could you note the actual commands to do so?? – merry-go-round Apr 22 '19 at 18:46
  • 1
    Possible duplicate of [Detach (move) subdirectory into separate Git repository](https://stackoverflow.com/questions/359424/detach-move-subdirectory-into-separate-git-repository) – phd Apr 22 '19 at 19:01
  • I would first create a new local branch from master: git checkout -b [name] Then move the files and add them all: git add -A Then commit the files: git commit -m '[message]' Then push the branch to remote: git push origin [branchname] Now your changes are on a separate branch on the remote. You can rebase or merge them into master. First checkout master: git checkout master And then merge (or rebase, I prefer merging): git merge [branchname] Everything should be in order now, see if your changes made it to your local master and then push master to the remote (git push)! – KeukenkastjeXYZ Apr 22 '19 at 19:01
  • Resources used: https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches https://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add https://git-scm.com/docs/git-merge – KeukenkastjeXYZ Apr 22 '19 at 19:02

2 Answers2

2

Checkout all branches then run:

git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter ABC -- --all

Detach (move) subdirectory into separate Git repository

EncryptedWatermelon
  • 4,788
  • 1
  • 12
  • 28
  • can you plz elaborate more??? The post doesn't explain much and doesn't make sense :( Pretty sure the command you gave me doesn't work. – merry-go-round Apr 22 '19 at 21:26
  • Did you look at the link I attached? More than enough info in there. – EncryptedWatermelon Apr 22 '19 at 21:34
  • It's tooooo complicated and I don't know how to apply it to my case :( Sorry – merry-go-round Apr 22 '19 at 21:35
  • Clone a new copy of your repo. Checkout every bench you care about. Most likely all. `git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter ab/doctor -- --all` This will create a new repo containing ab/doctor. Set origin to a new bare repo. `git remote set-url origin PATH_TO_REPO.git` Then push. `git push -all` Push tags. `git push --tags`. Repeat for other directory – EncryptedWatermelon Apr 22 '19 at 21:39
1

You want to use 'git subtree split'

git subtree split --prefix dir-to-extract -b selective-history 

Source: https://cjohansen.no/git-subtree-multiple-dirs/

Philippe
  • 28,207
  • 6
  • 54
  • 78