[SOLVED] Moving files github

I am not familiar with git command line as I use a gui to do everything git up to now.

I have reached a point where I will need to move all the files in existing folders, including images(binary), into new folders.

I am reading conflicting statements that I will lose history no matter how this is done and others saying git mv will retain the history.

I would appreciate input from the git pro users here to prevent me from destroying all this history if possible.

I will be testing this all on a clone until positive of the results.

1 Like

I should say, the target folder name of one folder will change from the original folder name.

git mv will keep the history. Else it would be useless.

Most of the time even if you move the file yourself, git rm the old one, and git add the new one… git is smart enough to know it is the same file. (and keep the history)

…but always better to git mv to be sure.

Caveat: all of this assumes the move is within the same repository. Moving stuff from one repository to another and keeping history is a lot trickier (though I’ve done it: see blender loader as a working result of that)


I found a great article on mv to other repo and keeping histoy just not within same.

I will try it on some clones. I am going to try to do it using a github virtual environment git command to see if that would work.

You probably won’t find many good articles on moving within a repository and keeping history because it’s automatic.

As I know, Git doesn’t care about the way how you’ve made change. It calculates the difference and finds matches by its own algorithm. When you see in a Git history (using git log, for example) that file was moved - that’s because Git detects very similar content with different pathname through the history, not because you’ve made a change with mv. All these commands rm, mv, add are just a convenient way to choose which files (or even lines) should be included to next commit and nothing more.

Well I have tried using git mv from an environment, git mv from the GitHub Web Interface, and from the git cli.

All wiped out history.

By history I mean when I click the file from the web interface, before the move, it will list all commits for any file selected. Afterwards, the history still shows in the history tab of the github desktop, and atom editor, but the history button on the web interface is wiped out only showing the last commit.

hmm @mitm it seems I was wrong -

Support `git --follow` to preserve history across renames · Issue #900 · isaacs/github · GitHub
Show file history for renamed files - How to use Git and GitHub - GitHub Support Community

It’s the GitHub ui that’s the issue, so what you’re doing is working, and is visible with git log --follow

1 Like

err. 3 years later and such a basic thing as keeping history is still not implemented?

I just checked and info shows correct from cli but its wiped out online.

Any suggestions on where to go from here?

I assume at some point they’ll implement it… Or not. Nothing that we can do. The history is safe though.

Gitlab has this feature and I imagine GitHub wants to maintain their competition with them, so I think at some point they’ll get to it :slight_smile:

Ok, thanks, ill keep moving then.

Ok, this is why I hate CLI so much, everything I read says “Hey, renaming a folder from CLI is easy!”

That tells me what I am doing must be wrong or there is something else thats changed in git and everybody but me knows the secret.

git mv oldname newname


git mv -f oldname newname

Rather than renaming oldname to newname, it just creates a new directory newname and moves oldname into it. Nothing in any doc says this is expected behavior unless the folder already exists, but it doesnt.

nvm got it. Delete from a windows shell says file deletes but silently fails, the folder is not deleted. Have to delete it from the windows explorer. What a crock of …

How did you delete it?

I delete folders from the windows command line all the time. 99% of the time I delete a folder it’s from the windows command line.

I had to go through windows explorer. Every delete shows success until I did a dir command and saw it was still there.

How did you delete it from the command line that didn’t work so I can show you what you did wrong so that you can properly delete directory from the command line in the future?

Not how you did it that worked that I already know.

oh sorry,

del filename

Which brings up the “Are you sure prompt y/n?”
enter y
Still silently fails.

del filename
…deletes all files in the directory. It’s the same as:
del filename/*

If you want to remove a directory then you use
rd filename
(Edit: and note the directory must be empty for rd to work)

…or have cygwin installed and do:
rm -rf filename

1 Like

Heh, sheesh. WTF, I figured you want to delete contents just do del filename/*.


I can tell now I am going to wipe my drive eventually.