mgi8ja
Last Updated: February 25, 2016
·
18.54K
· grevenx
Dsc 3654

Case-sensitive git in Mac OS X like a Pro

Found an awesome GIT tip for OSX users which are having problems with case-sensitivity and renaming of files. The issue occurs when you use the default OS X disk format (case-preserving, but not case-sensitive) and try to rename a file or folder in git by changing letters to uppercase/lowercase.

A typical hack around the issue is to execute multiple commands:

git mv filename filename_tmp
git mv filename_tmp Filename
git commit -m "Set correct case for filename"

gives no guarantee that it won't f*ck up any other users checkout which most likely need to remove the file or checkout a clean copy of the git repo.
However this approach caused me major headaches when I was doing a pull-request and had to squash my commits before pushing it (and one commit included the case changes to filenames). I did not find a good way to fix this problem. Also, other people in your team will not get the filename changes you just comitted on a git pull. So, a new approach to the solution!

Enter the world of read-write disk image using Disk Utility and use this newly created volume as your base working directory for working with git-repos! If all OS X users in your oragnization/company uses this approach, you should be good!

Here's what you do:

  • Launch Disk Utility
  • Choose "New Image"
  • Enter a nice Name for your Volume, e.g "Workspace"
  • Set the size to something that will most likely fit your needs (resizing is a whole another story)
  • Select "Mac OS Extended (Case-sensitive, Journaled)" in "Format".
  • Select "Single Partition - Apple Partition Map" in "Partitions"
  • Ensure "sparse bundle disk image" is set in "Image Format".
  • Save it somewhere on your hard drive

Now, when you mount this disk image you can move all your git repos over to this Volume to enjoy a git that doesn't get confused by those pesky case-changes!

(PS: You can choose to add the Disk Image created to your Login Items in the OS X System Preferences to have it automatically mount on boot)

Update: My new favorite way of dealing with this is to buy a Nifty MiniDrive microSD card adapter that allows you to always have with you an extra harddrive without anything "sticking out" of your macbook. With this option I always carry a extra 64 GB drive volume formatted as Mac OS Extended (Case-sensitive, Journaled) which I use for my git projects.

Say Thanks
Respond

10 Responses
Add your response

8263
Dsc 3654

@SaberUK That's also an option, that's why I recommended creating an Disk Image, not formatting your main drive :)

over 1 year ago ·
8268
16d031b5434f37b1128f4c498666f074

If you make two commits, then other users will also be fine.

over 1 year ago ·
8929
Mahmoud kassem photo

You can use:

git mv --force filename Filename
git commit -m "Set correct case for filename"

and a git pull for this change would also rename the file for other OS X users.

over 1 year ago ·
14471
Fcb0c26b4af62dd8288e1c5cc0379c66

Hi there,
well done. made my day for a symfony project.
Thanks !

Wisebes

over 1 year ago ·
14535
55063 3803523808619 773811908 o 1

This is amazing! Thank you for this!
If you work with unix in any way and work on a mac highly recommended!

over 1 year ago ·
15593
Wosrjv28 normal

We have issues in certain programs because they don't see file changes automatically.
Any idea how to fix this?

over 1 year ago ·
16863
None

You need to issue a "git config core.ignorecase false" if your Git repository is configured to ignore case in filenames. Otherwise the commit will break with "fatal: Will not add file alias 'Filename' ('filename' already exists in index)"

over 1 year ago ·
17472
None

awesome. thanks for the tip!

over 1 year ago ·
20790
0 n ohbbt2btgg0myp99dubxpmfcf00eyp9kobbxgo4brfh2wy4qvxjknrd27hy7grvah9z raed y

Be careful with the double-commit and ignoring cases here.
Linux kernel sources contain files that have both all-caps and small-caps versions.
Using what double commit or ignore cases will mess up your/kernel code.
check those out:
modified: include/uapi/linux/netfilter/xtCONNMARK.h
modified: include/uapi/linux/netfilter/xt
DSCP.h
modified: include/uapi/linux/netfilter/xtMARK.h
modified: include/uapi/linux/netfilter/xt
RATEEST.h
modified: include/uapi/linux/netfilter/xtTCPMSS.h
modified: include/uapi/linux/netfilter
ipv4/iptECN.h
modified: include/uapi/linux/netfilter
ipv4/iptTTL.h
modified: include/uapi/linux/netfilter
ipv6/ip6tHL.h
modified: net/netfilter/xt
DSCP.c
modified: net/netfilter/xtHL.c
modified: net/netfilter/xt
RATEEST.c
modified: net/netfilter/xt_TCPMSS.c

over 1 year ago ·
20795
Dsc 3654

@BobbyMarinov if you actually read the tip, it's not about using double-commiting at all and explains some of the troubles with it...

over 1 year ago ·
Filed Under