Logo Questions Linux Laravel Mysql Ubuntu Git Menu

git subtree split - the tags are not transferred

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:

enter image description here

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.

like image 381
sashoalm Avatar asked Oct 20 '22 17:10


2 Answers

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.

like image 117
Maic López Sáenz Avatar answered Oct 24 '22 00:10

Maic López Sáenz

I tried

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.

like image 38
Uga Buga Avatar answered Oct 23 '22 22:10

Uga Buga