Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git move all content one level up, for all branches

I want to move all the content in a git repository one level up, and need this to apply for every branch I have. Literally, I have:

+--repo
+----+.git
+----+folder
+--------+ A
+--------+ B

And I want simply:

+--repo
+----+.git
+----+A
+----+B

This post How can I move all git content one-level up in the folder hierarchy? has an nice answer, suggesting to do:

git mv folder/* ./ -k

Now how do I do with all the branches? I can think of:

  • do the git mv for master, then git rebase for all, on master

  • do the git mv for all branches?

Is there an advantage of one over the other? I saw also some answers based on git filter-branch --index-filter (answer here) but don;t understand how to apply it to my case.

Thanks!

like image 845
Matifou Avatar asked Oct 31 '18 05:10

Matifou


1 Answers

I would use the new git filter-repo, which does replace the old git filter-branch or BFG.

It comes with many usage examples, including path-based filtering, in order for you to move folder content to the top (assuming the top directory only includes folder)

cd /path/to/second/clone
git filter-repo --path-rename folder/:

By default, git filter-repo applies to all branches.

like image 81
VonC Avatar answered Oct 21 '22 18:10

VonC