Stevoisiak
Stevoisiak

Reputation: 26742

How can I move the root of my git repository up one level? (without moving subfolders)

I have a local Git repository with the following folder structure.

kronos
|-- org_maps
|   |-- attach_departments.ahk
|   `-- attach_jobs.ahk
|-- org_sets
|   `-- create_org_sets.ahk
`-- labor_level_sets
    `-- create_labor_sets.ahk

I want to expand the scope of my Git repository by moving my root folder up one level.

scripts
|-- kronos
|   |-- org_maps
|   |   |-- attach_departments.ahk
|   |   `-- attach_jobs.ahk
|   |-- org_sets
|   |   `-- create_org_sets.ahk
|   `-- labor_level_sets
|       `-- create_labor_sets.ahk
`-- peoplesoft
    `-- kronos
        `-- add_elig_departments.ahk

I've read How can I move the root of my git repository?, but the top answer suggests rewriting history which I would like to avoid.

How can I move the root of my git repository up one level without relocating my existing files and subfolders?

Upvotes: 3

Views: 1558

Answers (1)

Mark Adelsberger
Mark Adelsberger

Reputation: 45659

I think I understand what you want to do, based mostly on your directory tree diagrams. It sounds like you have an existing directory structure, in which you don't want to relocate any files; but you want git to see the files it has now, plus the directory above the files you have now.

I strongly advise backing up before doing this, but here is a procedure that I believe will work (and was ok in my tests), as long as you're not doing anything exotic:

cd .../scripts
mv kronos/.git .
git add .

Now if you do a git status, it should show that you've "renamed" everything in the repo, moving each under a kronos/ directory, and added the other files from scripts. If it looks like, you can commit.

Upvotes: 8

Related Questions