Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move Git repository up 3 levels from current folder, preserving history and adding new files

Tags:

git

I know there are many similar topics to this one, but I couldn't find an answer to my situation. Using git 1.8.3.1 I have a git repo in:

/path/to/my/git/repo/.git

I want to move the repository to /path/.git

while preserving the history of the original repo + adding new files from the new root directory. I've tried simply moving the .git folder to the appropriate place, re-add all files and committing but I've lost the history of my original repo.

How can I do this properly? (filter-branch?)

Thanks

UPDATE #1 My intention is to keep the files where they are, and expand the repo to include its parent directories + keeping history of the nested files:

Old repo: /path/to/my/git/repo/

New repo: /path/

UPDATE #2 I was thinking maybe there is a simpler solution than this, without moving actual files.

like image 532
amirb Avatar asked Sep 18 '25 18:09

amirb


1 Answers

So, basically there are two steps here:

A. Move files which are under git, so that git repo has correct root:

cd  /path/to/my/git/repo/
mkdir -p to/my/git/repo/
git mv * to/my/git/repo/
git status #check all files are moved.
git commit -m "megamove!!!"

B. Move the result into correct position:

mv * /path/
cd /path/
rm -r to/my/git/repo/ #drop empty dir

Also, another approach, more straightforward (but sometimes it could be not very nice if you have wrong CRLF):

mv /path/to/my/git/repo/.git /path/
cd /path
git add -A
git status #check all files are moved.
git commit -m "megamove!!!"

History should be preserved, check it with git log -M

like image 193
kan Avatar answered Sep 20 '25 13:09

kan