Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I move the .git folder to a parent folder without losing history?

Tags:

git

My local git repository looks like this

C:\MyRepo
      \MyProject
           \.git
           \ProjectFolder1
           \ProjectFolder2
           \ProjectFolder3

Now I want to add few folders which needs to be directly under "MyRepo" and needs to be part of same repository. I guess that means .git folder should also go directly under "MyRepo"

C:\MyRepo
     \.git
     \NewFolder1
     \NewFolder2
     \MyProject
           \ProjectFolder1
           \ProjectFolder2
           \ProjectFolder3

How do I move the .git folder up a level without losing the history?

I'm using Windows OS and git version is 2.6.3.windows.1

like image 621
LP13 Avatar asked Dec 11 '15 17:12

LP13


People also ask

How do I rename a directory in git without losing history?

The short answer is NO. It is not possible to rename a file in Git and remember the history.


1 Answers

You can move all your files to an inner MyProject folder before moving the git repo. Something like this might work:

cd C:\MyRepo\MyProject
mkdir MyProject
git mv -k * MyProject
git commit
move .git ..
cd MyProject
move * ..
cd ..
rmdir MyProject
cd ..
git add NewFolder1 NewFolder2
git commit

See also How to import existing Git repository into another?

like image 108
Etienne Laurin Avatar answered Oct 22 '22 16:10

Etienne Laurin