3

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?

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
  • What was the problem with `git mv` (which is the right way to do what you want)? – Leon Aug 28 '17 at 15:02
  • @Leon Doesn't `git mv` also move all of my subfolders? I'm trying to move from ``U:\Documents\Scripts\Kronos\`` to ``U:\Documents\Scripts\`` – Stevoisiak Aug 28 '17 at 15:02
  • It moves what you tell it to. If you need to move all subfolders, then what's the problem? – Leon Aug 28 '17 at 15:03
  • You just need to do it correctly - create a `kronos` subdirectory inside your current root directory and `git mv` all preexisting subdirectories into it. Then move `peoplesoft` into the root `kronos` directory and `git add` it. Then rename the top-level `kronos` to `scripts` and move it one level up (replacing the original `scripts` directory). – Leon Aug 28 '17 at 15:09
  • @Leon - You're looking at this only from the repo's point of view. OP appears to be trying to expand the scope of the repo within an existing directory structure that they don't want to disturb. – Mark Adelsberger Aug 28 '17 at 15:10
  • Though, [Mark Adelsberger's answer](https://stackoverflow.com/a/45922143/6394138) should be a faster and more straightforward way of doing the same thing. – Leon Aug 28 '17 at 15:16
  • @Leon I recommend posting your solution as an alternate answer. It's a perfectly valid solution, and may be helpful for future readers who may have issues with the commands line. – Stevoisiak Aug 28 '17 at 15:39

1 Answers1

8

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.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • [This worked exactly as expected](https://i.stack.imgur.com/8ErDD.png). I split the migration into two separate commits. (one for moving the root directory, and one for adding the PeopleSoft folder) – Stevoisiak Aug 28 '17 at 15:22