I have a git project that has one big root directory:
And then all the files and subdirectories are inside
C:\MyProject\MyProject. I want to remove that redundant root directory, so I used this command:
git subtree split -P MyProject -b MyBranch
git checkout MyBranch
git branch -D master
git branch -m MyBranch master
There is a problem with this solution, however - the tags are still attached to the now-deleted, original master branch:
The gray branch is the original master branch, the red branch is the new one without the redundant directory, but the tags are still attached to the old branch's checkins.
git filter-branch might be able to do the movement you want and migrate all branches and other references, like tags. The
--subdirectory-filter will do an operation similar to the subtree that you are creating:
git filter-branch --prune-empty --subdirectory-filter subDirectory -- --all
Check this other answer for better detail on how to setup the repository for this kind of operation.
git filter-branch --prune-empty --subdirectory-filter <ProjectSubFolder>
--tag-name-filter cat -- --branches
That transfered the tags too but kept a dangling branch with tracking references so I removed by hand the file .git\refs\original\refs\heads\master and the dangling branch dissappeared.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!Donate Us With