Git over SSHFS
While working at NCAR, I stumbled into a situation where I needed to use Git over an sshfs mounted directory. After beating on git and looking at its source code and not making much progress, I finally found a very simple solution related to how I mount the sshfs directory.
I’ve been working on a codebase at NCAR for my summer SiParCS internship that is based in an Subversion repository. However, the code I have is unreleased and I haven’t been given commit access to the repo. Also, I hate the feeling of working on code that isn’t properly versioned as I’ve lost work one too many times and never want that to happen again.
While working, I found myself needing multiple versions of some code I was working on (where each version was gathering different sets of data). Rather than commenting in/out various sections of the code, git branches would work perfectly in this situation.
Keep in mind that the code I’m working on resides on an AIX front-end node to a reasonably powerful supercomputer. The tool support on this machine is lacking, I have no zsh, updated vim, git, etc. To get around this tool deficiency, I mount the code I’m working on locally on my machine using sshfs. This works great! However… I still have no version control, so I decide to attempt to add the code to a git repository.
I started by removing the .svn directories using one of my favorite shell aliases, svnnuke. I then created a git repo with git init. So far so good. Finally, I attempted to add all of the files to the repo for the initial commit with git add .. However, this produced the error: 'fatal: Unable to write new index file'. After searching through the git source for the location of the error string and trying many variations of various git commands, I was stuck.
This morning I approached the problem again, from a different angle. I realized the problem was most likely not with git, but with the fact that I’m working over sshfs. Therefore, I may solve the problem with how I am mounting the remote filesystem. I googled for ‘git sshfs’ and found an article discussing Bazaar and SSHFS. This article containted the solution to my problem: mount the remote filesystem using sshfs with the -oworkaround=rename option. Poof! Git is suddenly working and I’m hacking on the code versioned under git and all its glory!

I ran into a similar problem. My remote machine lacks many of the useful tools on my local development machine, namely vim and git.
However I have the added problem of working on a shared server and am limited to a user account that is not in the sudoers file. Since the account that I develop with on my machine is not the same as my account on the remote server, git was failing with a “could not commit config file” error.
So, on my local machine, I created a user and group to mimic the user and group on the remote machine. (Notice that I am already root. If you don’t like to roll as root, you’ll have to use sudo).
root@bitbox: addgroup –gid=1235 studmuffins
root@bitbox: adduser andrew –uid=1234 –ingroup studmuffins
Then, I had to add a couple more options to the sshfs command in addition to the workaround:
root@bitbox: sshfs -o workaround=rename -o allow_other -o uid=1234 -o gid=1235 andrew@shittyhost.com:/path/to/remote/dir /path/to/local/mountpoint
So far, this seems to be working. But a WARNING to everybody using git over sshfs is very, veeeeery, sloooooooooooooooooowwwwwwww. For instance, I tried doing:
git add *
It took about 30 minutes for a 60MB project, only to fail entirely due to permission issues on a single file. Suck.
Ouch, sounds like even more of a restricted setup than I had. Thanks for the additional tips. Yes, I did notice that git over sshfs was a bit slower. However, I didn’t have ~50mb projects, so I probably didn’t see as much of an impact as you did.
Thanks for publishing this tip! Just saved me a lot of time and frustration…
You might want to use option “-o noforget” too. See this thread:
On marc.info:
http://marc.info/?l=git&m=129789551203755&w=2
http://marc.info/?t=129789546800002&r=1&w=2
Or on gmane:
http://thread.gmane.org/gmane.comp.file-systems.fuse.sshfs/1136
Me = happy camper
Nice tip.
Thank you !