I am following this: https://docs.github.com/en/get-started/using-git/splitting-a-subfolder-out-into-a-new-repository
I have a repository called my-repo
The structure of the directories below it is as:
MyProject
|
------ UI
|
------ DB
|
------ SERVER
|
------ ANDROID
I want to split ANDROID directory above into its own new repository called my-repo-android
I did the following for it:
Cloned the repository
git clone [email protected]:myproject/my-repo.gitGo into that directory:
cd my-repoRemove origin to avoid any push by mistake
git remote rm originRun filter repo command
git filter-repo --path MyProject/ANDROID --path-rename ANDROID/:
The command runs successfully. However, instead of getting the root directory as ANDROID, I still see the directory as MyProject/ANDROID with everything else removed.
What am I doing wrong?
How to use filter-repo path-rename option correctly so that the project structure changes from MyProject\ANDROID to directly ANDROID directory at the root ?
Edit:
The following command as per comments and answer below worked:
git filter-repo --path MyProject/ANDROID/ --path-rename MyProject/ANDROID/:ANDROID/
After this, I created a new repository remotely and ran the following commands:
Add remote origin
git remote add origin [email protected]:mypronect/androidRepo.gitMaster branch
git branch -M masterPull first
git pull origin master --allow-unrelated-historiesPush
git push -u origin master
Now I can see ANDROID directory correctly on the new androidRepo on bitbucket.
And when I open any file, I can see the history as well. Thus filter-repo has worked as expected.
However, I only see master branch. I do not see any of the other historical branches and tags. (We tag/create a separate branch for every release we do).
What am I missing? How can I preserve all branches and tags related to ANDROID as well ?
I tried the following command, but it didn't work:
git push --all origin
You forgot
MyProjectbeforeANDROIDin the--path-renameoption. With--path MyProject/ANDROIDyou are tellingfilter-repoto keep only the pathMyProject/ANDROIDfolder.--path-rename ANDROID/:you are converting theANDROIDfolder to the root folder basically.My guess is that you
filter-repois not findingANDROIDfolder, because it is insideMyProject, and therefore it is not able to rename it.Final command might be:
Or, the corresponding shortcut:
EDIT: I thought you wanted to make the content of the
ANDROIDfolder as the root, instead it seems you want to move theANDROIDfolder from./MyProjectto./. In this case @LeGEC gets the point with--path-rename MyProject/ANDROID:ANDROID.