Git Moving Files into Folders

I am quite new to git and version control in general, and have question about moving files around. I have a master repo on GitHub, with 6 source files.

I’ve done a lot of work on the project and now my local branch contains two folders with the sources in those.

  • “Alias” git authors/committers?
  • How can I do case insensitive git diffing?
  • Delete username from a Git repository
  • git apply does output nothing and does not patch anything
  • Skip to next modified file in git diff?
  • Subversion or Mercurial SPI - What API shall a server implement?
  • The directory structure used to be like:


    • File 1
    • File 2
    • File 3
    • File 4
    • File 5
    • File 6

    Where as my local branch now looks like this:

    New Folder 1:

    • New File 1
    • New File 2
    • New File 3

    New Folder 2:

    • File 1
    • File 2
    • File 3
    • File 4
    • File 5
    • File 6

    How can I move my local structure to the master branch without losing my commit history on the old files?

  • Best practices for maintaining configuration of embedded linux system for production
  • How to make git show to use formatting?
  • Laravel different environment git .env Xampp & Mamp
  • How can I grant access to a remote git repo?
  • Using SVN to connect to a git repository
  • private folder in github
  • 4 Solutions collect form web for “Git Moving Files into Folders”

    Just commit. Git blame etc will generally do a pretty good job of automatically detecting moves.

    git doesn’t actually track “moves” of files, it infers it on demand from similar content. So, just make the move and add / remove files as appropriate. (You will make life easier for the tools in future if you avoid making changes to the content as well as moving them in a single commit.)

    Then, to see the log accounting for moves, use -M, -C, or their variants to git log. Similar flags apply to other tools, and you should read the help to understand the detail of what they do.

    If you use git mv on a file, it just does the git rm and git add for you.

    The other posters are correct, however if you want to confirm that git is going to see these as moves (and not a combination of delete/create), run a git status. You should see:

    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #   renamed:    oldfile.txt -> newFolder/newfile.txt

    In github, if you don’t have too many files to move, an interesting alternative is to Edit the file, and change it’s name to:


    When you commit, the file is moved to the folder. If the folder doesn’t exist, it will be created.

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