4

I had duplicate directories in Github (differing in case). It seems they are both tracked to a single directory in my local. How do I properly delete one of the directories without affecting my local?

General steps I took (IIRC):

  1. I had a directory, let's say "MyDirectory".
  2. I pushed some code in that directory to Github.
  3. I changed the directory name to "mydirectory".
  4. I realized that github is not case-sensitive by default (all my code changes were added to to "MyDirectory" in Github), so I ran "git config core.ignorecase false".
  5. I re-pushed the changes, which created a new directory in Github. (At this point, Github has 2 directories, one named MyDirectory and the other named mydirectory. My local only has mydirectory.)
  6. I couldn't figure out a good way to delete MyDirectory from Github, so I manually deleted all the files inside it following these steps.
  7. Now, when I run git pull, it deletes mydirectory from local (I don't want that.)
torek
  • 448,244
  • 59
  • 642
  • 775
Azianese
  • 554
  • 7
  • 21
  • 2
    Several clarifications: 1. "GitHub is not case-sensitive by default" is not accurate. The problem lies in your operating system's file system and how git interacts with it, not GitHub. 2. `git` does not track directories. It only tracks the contents of files. So the only way to remove a directory is to delete the files in that directory. – Code-Apprentice Jul 16 '19 at 23:18
  • 1
    https://stackoverflow.com/questions/11183788/in-a-git-repository-how-to-properly-rename-a-directory/11183844 might be helpful as well as the links from that page. – Code-Apprentice Jul 16 '19 at 23:22
  • 1
    Yes, you do want that. Copy out all the files, delete both your local duplicate directories, pull, now everything is in sync. Now make the directory again, once, and put the stuff in it and push. – matt Jul 16 '19 at 23:31
  • 2
    *Don't* do what you did in step 4. The `core.ignorecase` setting in your Git repository tells your Git how *your* computer *actually behaves*. Changing it means you're lying to your Git: it won't change how your computer behaves; it will only change the strategies Git uses to try to deal with how your computer behaves, perhaps making Git behave badly. – torek Jul 16 '19 at 23:48
  • 1
    @Code-Apprentice Thanks for the corrections. It seems I need to educate myself more on how git works. matt, That's pretty much what I ended up doing. Thanks. torek, I see. That, along with Code-Apprentice's answer, explains why the remote changes would lead to deleting my local files after git pull. I guess I should be using "git mv" when I run into this problem in the future. – Azianese Jul 17 '19 at 00:00
  • @Azianese I posted a pseudo-answer that adds some detail to my comments above. – Code-Apprentice Jul 17 '19 at 15:32

1 Answers1

3

TLDR: Don't set core.ignorecase=false. This is opposite of what your operating system actually does and causes git to behave unexpectedly.

I think there is some confusion here about file names, Git, and GitHub.

  1. The file system from your operating system: Linux and Mac use case-sensitive file names. Windows file names are case-insensitive.

  2. Git: Git has a configuration called core.ignorecase that you can set. This is used to inform Git about the behavior of your operating system. If you set it opposite of what your operating system actually does, then Git will behave in unexpected ways. Note that this doesn't modify the case sensitivity of the underlying file system.

  3. Git Hub: This is a web service that is built on top of Git. For this discussion, it is not really a factor as case sensitivity of file names is not managed at this level.

Additionally, Git does only tracks file contents. It does not track directories directly. The only way to remove a directory from Git's version control is to remove the files from that directory.

I know this doesn't directly answer your question, but I hope it clarifies how these three pieces contribute to the issue.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268