Search code examples
gitrebase

Changed and Renamed directory on local GIT branch. Now I want original directory PLUS the changed one


  • In a new local branch, I made a bunch of code changes in a directory and renamed that directory locally.
  • The remote branch remains untouched -- I have not merged anything. My new directory does not exist there.
  • Now I want both directories: the new one (with its history) and the old one (in its original state with its original name).

How can I achieve this outcome with GIT?

Thank you.

I tried branching off of the original branch and merging it with my local branch. I tried pulling the remote branch into my local branch. I'm trying to avoid reconstructing all of my work manually on a fresh branch off the old directory.


Solution

  • In your new branch, add and commit if you haven't already.

    Switch to the other branch, the old one that still contains the old directory with the old name.

    git switch oldbranch
    

    Now you can see the old directory with the old name, right there in your working tree. Move the directory to a new location outside your working tree.

    Now

    git reset --hard
    git switch -
    

    Now you're back where you were, in the new branch with the new version of the directory. Move the old directory back into your working tree. Done. You now have both.