I
I
ijakparov2016-08-11 09:23:30
git
ijakparov, 2016-08-11 09:23:30

How to move a Git repository up a level, including new folders?

Hello!
There is a project structure:

  • dir1 - move the repository to this folder
    • file1.txt
    • dir2
    • dir3 - the repository is in this folder
      • file2.txt
      • .git



How can I move the repository from the dir3 folder to the dir1 folder without having to re-initialize it? It is necessary to add all new folders from dir1 to git and also make sure that the commit history from git3 does not break.
If it turns out to do this, then how to push it to the remote repository, overwriting everything there.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Zolotykh, 2016-08-11
@ijakparov

Create another dir3 inside dir3, move everything except git there, rename the original dir3 -> dir1, place the files a level higher in the renamed dir3 in dir1.

I
ijakparov, 2016-08-11
@ijakparov

Everything works, I note that copying should be done as follows:
create a new directory (adding a dot to the beginning of its name so as not to get errors in the next step):
$ mkdir .dir3
move all the contents of the current directory to this directory:
$ git mv * .dir3
rename the directory, removing the first character - the dot - from its name:
$ git mv .dir3 dir3
check if everything is correct:
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# renamed: dir/index.html -> docroot/dir/index.html
# renamed: index.html -> docroot/index.html
#
do a git commit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question