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.

  • How does git handle folder permission?
  • Why isn't tilde (~) expanding inside double quotes?
  • Can I change the default directory on my local drive for all Git activity?
  • Using git-svn without “trunk” sub-directory
  • how to push all files in a folder to all git branches
  • How do I preserve DIRECTORY file mode or permission in git?
  • 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

  • Test if a remote repository known by a URL contains a commit by hash
  • Workflow with git-flow feature branches and Gerrit
  • Git pull fails : unable to update local ref
  • Why this import of huge sources fails on GitHub?
  • What's the -practical- difference between a Bare and non-Bare repository?
  • Why does cherry-pick tell me that I have all lines changed?
  • 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.