If I understand correctly want you want to achieve, I think you should try the --subdirectory-filter
of the filter-branch
command :
git filter-branch -f --subdirectory-filter "src/" --prune-empty -- --all
Replace src/
with the name of your subdirectory. The option --all
will perform the action on all branches.
Hope this helps.
EDIT:
The command will only change the root directory of your local branches. If you want to change the root directory for all remote branches, I suggest you use this trick :
- first you clone the remote repository with the
--mirror
option, which leads to a bare local repositorey with all branches,
- and then you make this local repository a regular one.
Thenin this newly cloned repository that contains all branches, you can apply the filter-branch
command.
With the option --subdirectory-filter
, this command will set the specified subdirectory as root of the local git repo.
The --prune-empty
option will discard all commits that are empty (because they refers exclusively to files outside the subdirectory).
It is important to understand that all the git history will be rewritten as if the subdirectory were always the root of the git repo.
I hope I help you understand this command.