How do I move repository (old_rep) to another repository (new_rep) as a directory without loosing the history and files for repositories?
Here is what I tried from other stack questions. I have files in new_repo like directories, .txt, .sql files with history. When I run the codes below, looks like the --mirror is replacing everything from old_rep into new_rep.
mkdir foo
cd foo
git clone --bare ssh://[email protected]/test/old_rep.git
cd old_rep.git
git clone --bare ssh://[email protected]/test/new_rep.git
cd ..
rm -rf old_rep.git
Assuming you want to move all the content from old_repo
into the directory dir1
of new_repo
:
In old_repo
create dir1
, move all the files and directories from the working directory into dir1
and commit.
That's all with old_repo
. The other steps below happen in new_repo
.
In new_repo
use git remote add old_repo <path-to-old-repo>
to add the old repo as a remote for the new repo. Replace <path-to-old-repo>
with the actual path (full or relative) of the old repository. I assume you have both repositories on the local computer.
Make sure there are not uncommitted changes. If there are then commit them on a branch or stash them.
Run git fetch old_repo
to get the commits from the old repo into the new repo. Assuming you already have checked out the branch where you want to import the code from old_repo
, run git merge old_repo/master
. Replace master
with the actual branch from old_repo
you want to import.
Check that everything looks good in new_repo
and you have all the files from old_repo
and their history.
Cleanup. Only after you double-checked step 5, run git remote remove old_repo
to unlink the repos and then, if you are sure you don't need anything from old_repo
, you can remove the directory where old_repo
is located. I would do the removal after some time (1-2 weeks), just to make sure I don't lose anything.
That's all.
This is something I found to be a lot simpler. The answer below assumes like me you don't care too much for this old repo as much as I used to because it's old or the new repo is just storage for old repos. Which is why I don't mind doing it this way.
git add .
then git commit
and then git push
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With