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.

  • How to customise UnGit branch graph?
  • Unknown option git config --local reported by Jenkins
  • how to put an eclipse project into github
  • Seeking examples of workflow using git-format-patch and git am
  • Git: How to list commits on this branch but not from merged branches
  • Merging: Hg/Git vs. SVN
  • 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?

  • Git Alias to chain add, commit, pull, push?
  • Not able to detect branch from Git post-receive hook
  • List commits made by others (i.e. not me)?
  • PhpStorm Git keeps saying: no changes detected
  • How to combine group of local commits to single push in IDEA?
  • how to alias git checkout && git stash apply
  • 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.