How can I move the root of my git repository?

To start, I’m aware this question has been asked before here.
The thing is that I do like to keep the history.

So I tried out all of the other steps I could find which involve either moving the .git directory one level up or creating a subdirectory and moving all the files from the current root into that. But I keep on losing the history of my files.

  • Git add a folder with spaces in the name
  • Troubleshooting misplaced .git directory (nothing to commit)
  • Git does not recognize new folder adds and its sub directories
  • Best way to replace a whole directory tree in Subversion?
  • What's happened to my directory on GitHub?
  • git clone from->to directory confusion
  • The funny thing is that Git Bash (so on my local commmand line) tells me it detects the files as being renamed and when I run git log I also get the history of the file as I’d expect it. But when I look on github, the history is gone and the commit only contains a list of files being removed and added (instead of a list of renames, which I’d expect).

    The repository I’m talking about is this one. There’s a branch called “Moving” in which I tried to move the files around.

    In case it helps, the exact steps I took were:

    1. Create the subdirectory “src” in the directory which contains .git
    2. Move all the files into that subdirectory
    3. Move the directories from the level above where .git is, one level down
    4. Run a git add src and git add nbproject where src is the subdirectory I created in step 1 and nbproject a directory I moved down in step 3
    5. Run a git rm for all “old files”
    6. Run a git status and note that all files are detected as being renamed
    7. Run a git log src/README to make sure the history is OK
    8. Finally commit the change to github
    9. Note that the history is gone when I look at my README on github

  • Obtain the latest refspec on a Gerrit Change
  • Tracking history of a branch
  • Find which revision an export is from
  • “Key is invalid” message on GitHub
  • Is git stash branch-specific or for the whole repository?
  • Azure: Deploy from source control using Visual Studio Team Services
  • One Solution collect form web for “How can I move the root of my git repository?”

    Git does not store file copies and renames, it uses heuristics to figure that out. I speculate Github isn’t picking up the rename because they’ve turned off rename/copy heuristics to save processing power. It doesn’t affect much but how that one commit is displayed on Github. Simplest thing to do is just ignore it and keep on coding. Maybe contact Github tech support.

    Otherwise, your other option is to rewrite history to make your subdirectory the main directory. This will retain history but change all your commit IDs which may throw off references in log messages and issue trackers. (I do recall a tool that would change commit IDs in log messages, but I can’t remember it.)

    Git Baby is a git and github fan, let's start git clone.