Search code examples
djangogitgithubherokudirectory

GIT: Moving all content of a parent/subfolder to parent/


I am new to Github. I have uploaded my Django app to Github that I will be using on Heroku.

I successfully added files and folders on the web interface of Github but realized that I incorrectly uploaded folders.

I cloned my github repo on my local machine. I have a sub-folder that I want to move to it's parent folder but the git mv is not working for me or I am doing something wrong I can't figure out what.

parent folder: PH_Dorms
sub folder: ph_dorms

1st try:

cd PH_Dorms
git mv ph_dorms ../

Result: fatal: '../' is outside repository

2nd try:

cd PH_Dorms
git mv ph_dorms ./

Result: "fatal: can not move directory into itself, source=ph_dorms, destination=ph_dorms

3rd try:

cd PH_Dorms
cd ph_dorms
git mv ph_dorms ./

Result: fatal: can not move directory into itself, source=ph_dorms/ph_dorms, destination=ph_dorms/ph_dorms

4th try:

cd PH_Dorms
cd ph_dorms
git mv ph_dorms ../

Result: fatal: cannot move directory over file, source=ph_dorms/ph_dorms, destination=ph_dorms

5th try:

cd PH_Dorms
cd ph_dorms
git mv ph_dorms/* ../

Result: fatal: bad source, source=ph_dorms/ph_dorms/, destination=

6th try:

cd PH_Dorms
cd ph_dorms
git mv * ../

Result: fatal: bad source, source=ph_dorms/, destination=

7th try:

cd PH_Dorms
cd ph_dorms
git mv * ./

Result: fatal: bad source, source=ph_dorms/, destination=ph_dorms/

I gave up! Never tried something else. Here's the screenshot from Git CMD:

enter image description here

If you need additional information, please let me know.


Solution

  • From what I can gather your git repository's root only has one folder, ph_dorms, which has the rest of your project?

    This should do the trick:

    cd <path>/PH_Dorms
    shopt -s dotglob
    mv ph_dorms/* .
    rmdir -p ph_dorms
    git add --a
    git commit -m '<message>'
    git push
    

    The above moves the content of ph_dorms into the root and safely deletes the ph_dorms folder. Then it adds your changes to GitHub. To move filenames beginning with a dot . too in the current shell session, it necessary to run shopt -s dotglob first.