Some Bits: Nelson's log

16 posts about git

Claude automemory, Nix, and .git

I’m running into a complicated snarl of things in my server management. Long story short: both Claude and Nix make assumptions based on your current working directory and where the nearest .git folder are. You may want to manage that carefully.

Claude Code has a couple of features that are defined “per project”. The one I care about is automemory, where Claude records little things about your projects. The directory Claude attaches these memories to seems to be the top level directory that has something named .git in it. That means if you have git repos in nested directories, the memories are attached to the largest scope.

Nix also has features where it scans all the files in a directory with a .git in it, assuming they belong to the NixOS build you’re doing. This caused me various problems that I can’t really explain.

My fix for all of these is for a sever project like “caddy”, I have a directory with a .git repo in it called src/ai/servers/sfpve/caddy/repo. I launch Claude from inside src/ai/servers/sfpve/caddy, where there is no .git. The memories then attach up to the src/ai/servers/ parent directory where I want them. Claude Code itself is launching Nix and somehow this helps it manage Nix’s magic with .git.

It’s more complicated than that in reality and I don’t actually understand what I’ve done or whether it’s a good idea. But Claude using the location of a .git to decide where automemory goes was helpful for me to learn.

Promoting a git project to a bare repo

I usually develop on local disk, just git init and start programming. No push or pull, no remote repos. But sometimes I want to get fancy and have a remote repo. I don’t use GitHub or GitLab to host these projects, I just host them myself. But things have changed a bit in the intervening 12 years, here’s the new process.

### Clone existing code into a new bare repo
cd ~/gitrepos
git clone --bare ~/src/blog/static/flourish/ flourish

### Set up origin in the old existing code
cd ~/src/blog/static/flourish
git remote add origin example.com:~/gitrepos/flourish
git push --set-upstream origin main

### Verify things are working as expected
git remote -v
git branch -avv

One subtle thing there... The bare repo is created by cloning from local disk. But then I set the origin back in my working code via an SSH URL. Not strictly necessary in the case where both the bare repo and the working copy are on the same computer but the whole point here is to enable working copies on multiple machines from the same bare repo.

And an extra complication: I have Syncthing synchronizing my ~/src to my various Linux development environments. All behind the scenes, transparently. This can be a little spooky sometimes; if I git commit in one working copy there’s no need to git pull in another working copy because syncthing will sync for me. It’s harmless to git pull and git push in this configuration though, at least as long as I’m not making changes in two places at once.

Markdown processing in Python

I’m mad enough about Hugo I spent an hour writing a very minimal blog engine. Lots to go to make it usable, but as a piece of it I had to look for a Markdown processor for Python. Here’s what I’ve found, there are probably more. I want something that supports CommonMark and has a decent extension story. (A lot of folks support GitHub flavored markdown, perhaps that’s coherent enough to also be reasonable.)

mistletoe. 652 GitHub stars. I’ve used this already and it works but haven’t gotten in deep. Docs and PyPI niceties are not great. Says it’s the fastest implementation but all of these are pretty close (except Mistune which is way faster). Supports rendering to other targets like LaTeX, not just HTML.

markdown-it-py. 517 GitHub stars. Looks comprehensive, has a bunch of plugins. It’s a port from NodeJS code. Plugin code looks pretty complicated.

mdformat. 263 stars. Has plugins and code is connected somehow to markdown-it.

marko. 249 stars. Says it has very easy plugins and is not very fast but correct.

Mistune. 2300 stars. Not CommonMark but maybe reasonably so. Very fast. Plugins look awkward.

Not CommonMark: Markdown, Markdown2,

No real conclusion here. I’ll stick with mistletoe since I already have it working, then look to jump when I get to the part where I need my own plugins. marko or Mistune look most promising to me if mistletoe won’t work.

Update: some very simple evaluation

I did some quick tests comparing mistletoe, marko, markdown_it, and Mistune.

The output of all three were substantially similar. mistletoe emits actual ” ASCII quotes whereas the other two are outputing ". Which reminds me I need to enable typographic quotes.

Some very simple benchmarks show mistletoe and markdown_it takes 2-3x as long as mistune, marko is about 4x.
timeit 9000 byte input: mistune (1.13ms), markdown_it (2.78ms), mistletoe (3.60ms), marko (4.84ms)
1800 HTML posts: mistune (490ms), mistletoe (860ms), markdown_it (925ms), marko (2000ms)

Update 2: markdown_it

After reading docs and setting up typographical quotes I think I’ll go with markdown_it. I was turned off at first because it was a NodeJS port and its code seems quite complicated, they really want to explore details of parsers, ASTs, renderers to you. But it does typographical quotes right! And it’s fast and popular. Now that I’m over the learning hump it seems a good choice. I haven’t tried writing a plugin for it yet though.

Renaming git’s default branch

Here’s how to change git’s default branch for new projects to the name “main” to avoid unpleasant language. This will eventually become the default.

Run this code once in a shell. This will persist a change in your .gitconfig file.

git config --global init.defaultBranch main

To rename existing branches on a local repo it’s as simple as

git branch -m master main

Updating a remote branch name is a little more complicated.

git inhumanity: detaching your head

mike-the-headless-chicken1One of my favorite examples of git’s inhumane tool design is the warning

You are in ‘detached HEAD’ state.

WTF does that even mean? I do something as simple as wanting to look at a version of the code three revisions back and suddenly I’m decapitated? It’s an alarming bit of language, not to mention completely opaque.

Really the concept is pretty simple. The message could read “you checked out a version of the repo that doesn’t match the head of any named branch”. That would explain the state you’re in and be much less alarming. “Detached HEAD” is a shorter way of saying that, but is a bit of jargon that only makes sense to experts. The experts who don’t need that warning anyway.

The problem is git is designed by people who don’t see opacity as a problem. It’s like the Unix philosophy where “cat” mean “show file” and “rm” means “delete” and “grep” means “search”. I’ve internalized all those words 20+ years ago, but I’ve never forgotten how they are barriers to learning.

git pull: merge vs rebase

In my previous post I jumped through some hoops to do a “git fetch; git rebase” instead of a “git pull” so that I ended up without a merge commit in my timeline. (See explanation here). Those two commands are very manual, what else can we do?

One simple option is to do git pull --rebase, which rebases instead of merges.  However that can apparently cause problems depending on what’s in your local repo. I have no idea what rebase does if there would be a merge conflict.

The git up user-contributed command is another solution. I think at its heart it’s a wrapper for fetch + rebase, but it has some other smarts in it. No idea if it can cause problems.

This StackExchange answer has a much more thorough investigation. He recommends doing a git update followed by git merge --ff-only. I guess fast forwards are “safe”; using this flag prevents git from automatically creating a merge commit if it can’t fast forward. There’s a lot more detail there, worth a close read.

I’m going to follow the StackExchange recommendation of setting git config --global pull.ff only and see where that gets me. I think it’s entirely safe; if I do a pull the worst that will happen is I’m on my own to do a manual merge. I may still keep using that git up Ruby command, too.

And now my rant. Fuck git. It’s insane to me that you have to do this kind of contortion. The default obvious tool should be the right one. I hate the neckbeardy attitude you read in most git discussions where the Superior Nerd gets to say “actually, it’s complicated because it needs to be blah blah”. That’s crap; it’s complicated because git has a bad UI and a bit too many exposed sharp corners for civilian use. (I particularly like the StackExchange guy’s observation “Note that the purpose of Git is to make it easy to share and consume the evolution of a codebase, not to precisely record history exactly as it unfolded.”) Git is amazing in many ways and has enabled a lot of things, but I sure wish a more humane alternative were the popular one.

GitHub collaboration notes

After my whining about pull requests Mike gave me commit access to the repo. Here’s some quick notes on some simple git stuff he helped me do. The setup is we both started working in on separate projects. He made a private branch, made a bunch of changes, then pushed them to the ditch-node branch. Meanwhile I had made my own pyconform branch off of ditch-node before his changes and wanted to bring mine in with his. We could have just merged, but Mike asked me to rebase so that my changes came after his to keep the history tidy. That was easy because there were no conflicts. Here’s how it went.

# Push my pyconform branch up to GitHub
  506  git push -u origin pyconform

# Fetch Mike's changes in ditch-node
  507  git fetch origin ditch-node

# In my pyconform banch, rebase with the changes in ditch-node.
# This happened automatically without extra work on my part, no conflicts
# No commit necessary.
  510  git rebase origin/ditch-node

# Try to push my newly altered pyconform branch to GitHub
  513  git push
# That didn't work because we've altered history and Git is confused.
# So now we have to force the push to rewrite GitHub's version of things
  514  git push -f origin pyconform

# At this point my pyconform branch is done and looks as if I'd forked it off
# of Mike's changed, even though really we were working in parallel. Now it's
# time to merge my changes back to ditch-node and get rid of the pyconform branch

# Switch to ditch-node
  515  git checkout ditch-node
# Pull in the changes that are on GitHub
  516  git pull
# Merge from my pyconform branch
  517  git merge pyconform
# Push the merged commits back up to GitHub
  519  git push
# Delete my branch locally
  520  git branch -d pyconform
# Delete the branch on GitHub.
  521  git push origin pyconform
# Ooops, that didn't work, so do this magic to remotely delete the branch
  522  git push origin :pyconform

I regret not being more comfortable with this kind of git usage. I am sort of OK with git by myself but it’s a lot more complicated when collaborating.

GitHub pull requests are too heavyweight 2

New version of an old rant. The GitHub pull request model makes sense if you plan to submit one giant PR a week. It’s terrible for rapid collaboration. Today I wanted to submit a 5 line patch to openaddresses/machine, in the branch ditch-node. I already have a fork NelsonMinar/machine. I had to:

  1. Switch to master branch in my clone of NelsonMinar/machine
  2. In my clone, manually set up an upstream remote for master
  3. Pull changes from upstream merge them with a fast forard.
  4. Push the merge result back to GitHub
  5. Repeat steps 1-4 manually for the ditch-node branch. I guess you’re expected to do this manually for every branch you care about.
  6. Create a new branch in my clone. I branched off the ditch-node branch
  7. Make my changes and commit them.
  8. Push my new branch back to GitHub with “--set-upstream origin”
  9. Use the GitHub UI to create a pull request.
  10. Fix the pull request so it’s a diff against ditch-node, not master. Note the branch I’m creating the PR in was branched off of ditch-node; no idea why GitHub didn’t respect that.
  11. Submit the pull request. Never ever touch that branch again until it’s accepted.
  12. As a bonus, the project maintainer warns me he has to rebase my pull request so it’s going to break my fork until I update.

It’s too much work on GitHub to follow along some repo and make occasional friendly improvements to it. I could use some simplified workflow which is just “keep my forked repo updated at all times with upstream unless it would clobber some work I did”. I imagine I could write a script to do that.

Maybe GitHub expects frequent committers to have write access and not go through pull requests. I like the review and auditing of pull requests, though.

Update: John Firebaugh recommends git-up and git hub to help make this better.

Homebrew observations

You can’t move a Homebrew binary directory. I installed Homebrew in /usr/homebrew2 and then renamed that to /usr/homebrew and a bunch of stuff broke because it had the path /usr/homebrew2 baked into it. bash-completion, also python.

Many Homebrew packages don’t compile cleanly. I ran into three: mg, unison, and ggobi. I filed bugs and got prompt responses (and a patch for ggobi in 12 minutes!), which is pretty great. OTOH it feels to me like Homebrew doesn’t have any sort of automated build-and-test setup for packages, these were all really simple bugs that anyone installing the code would hit. Some basic integration testing would go a long way.

I’m very grateful to Homebrew but the whole project feels pretty ad hoc and brittle to me. No surprise since it started out being such a simple thing. And simple is good! But I think at this point it’s evolved into needing to be a serious package manager, but hasn’t yet evolved all the serious package management. I wish we’d just use dpkg on MacOS instead. Fink is exactly that, but my experiences with it have been bad.

Starting anew with a clean homebrew install. Note I’ve already set PATH and BREW to use /usr/homebrew, the non-standard location

sudo mkdir /usr/homebrew
sudo chown nelson /usr/homebrew
cd /usr/homebrew

git clone https://github.com/Homebrew/homebrew.git
mv homebrew/* homebrew/.git* .
rmdir homebrew

brew tap homebrew/dupes
brew install atk autoconf automake bash-completion cairo clens cloog faac ffmpeg fontconfig freetype freexl gdal gdbm gdk-pixbuf geos gettext gfortran ggobi giflib git glib gmp gobject-introspection gpp graphicsmagick grc gtk+ harfbuzz icu4c iftop isl jpeg jq json-c lame less libffi libgeotiff liblwgeom libmpc libpng libspatialite libtiff libtool libxml2 lzlib makedepend mp4v2 mpfr nmap node objective-caml openssl optipng ossp-uuid p7zip pango pgdbf pixman pkg-config postgis postgresql proj pv python readline rsync sqlite texi2html unrar wget x264 xvid xz yasm

brew install mg
brew install unison

Cloning a gist via ssh

For some reason GitHub really wants you to clone gists via https. But I’m all set up with ssh keys and would prefer to check out that way. Here’s how:

git clone git@github.com:5624141.git

Replace the number with your gist id, of course. Your username is not part of the URL.

playing with libgit2

Following on my dorking around with bash prompts yesterday, I was wondering how fast one could write a program to query state from git for the command prompt. The minimal __git_ps1 function I set up there takes about 75ms to run; takes longer if I add more to my prompt. That function works by invoking git a bunch of times, maybe a custom C binary could do better?

I took a quick crack at it using libgit2. It’s been years since I wrote any C code and it was rough going. No exceptions, no useful string type, manually allocated and typed memory, ugh. Maybe I should break down and do C++. Anyway, I managed to scratch together something that prints out the branch name and hash for the current commit. With caches warm my program takes just about 30ms to run; compare 23ms for __git_ps1 if it’s only printing branch name, nothing else. Ouch, I’m slower!

Using set -x I can see what __git_ps1 is doing. The main command its forking is git symbolic-ref HEAD, which takes 10ms if I run it by itself. I wonder why my libgit2 based code is so much slower?

I still feel a custom C binary should be faster, particularly to support fancier output info. But it’s an awful lot of pain writing libgit2 code in C, I may not have the patience to press on.

Update: derp, my program isn’t slow because it’s slow. It’s slow because I was running it on my Mac off of an SMB mounted volume. If I copy my binary to local disk it’s faster than stock git as expected: 6ms vs. 10ms for git symbolic-ref HEAD. Duh.

One other note; I started playing with dtruss/dtrace to figure out what system calls the two programs were running. My code makes 135 system calls, stock git makes 178. My code opens 8 files, 3 of them from the repo (which is still SMB and therefore slow). git opens 14 files, 6 from the repo. It seems to be doing all the work on the repo files twice, not sure why. Anyway now I’m reassured my libgit2 approach could be more efficient.

#include <stdio.h>
#include <stdlib.h>
#include <git2.h>

void check_return(int rc, char * msg) {
    if (rc != 0) {
        fprintf(stderr, "%s. Code: %d\n", msg, rc);
        exit(1);
    }
}

int main(int argc, char ** args) {
    int rc;
    git_repository *repo;
    git_reference *head;

    // open the repository
    rc = git_repository_open_ext(&repo, ".", 0, NULL);
    if (rc == GIT_ENOTFOUND) {
        // No git repo; that's OK.
        exit(0);
    }
    check_return(rc, "opening repository");

    // find HEAD
    rc = git_repository_head(&head, repo);
    check_return(rc, "finding HEAD");

    int ref_type = git_reference_type(head);
    if (ref_type == GIT_REF_SYMBOLIC) {
        check_return(-999, "Cant handle symbolic targets");
        // git_reference_symbolic_target() or git_reference_resolve()??
    } else if (ref_type == GIT_REF_OID) {
        // Get the name
        const char * name = git_reference_name(head);

        // Get the hash
        const git_oid * oid = git_reference_target(head);
        char hash[7];
        git_oid_tostr(hash, 7, oid);

        // Print out what we've learned
        printf("%s %s", name, hash);
    }

    return 0;
}

git prompts for bash

I’m trying to learn more about git. I thought it’d help me to modify my bash prompt to include git status. Turns out theres lots of ways to do that. I want something simple and minimal, but maybe using color. For years my prompt has been a simple “(hostname) = “; don’t want to go crazy. (Why =? Because it doesn’t look like $ or # or %, the standard characters. I know it’s mine.) Here’s some options.

  1. Here’s a blog post with some minimal git additions to the prompt. It just invokes git symbolic-ref to figure out the branch name. Simple, easy to understand, there’s a zillion hacks like this. Here’s another.
  2. git-prompt.sh is a bash addon distributed with git that adds a shell function __git_ps1 that can be invoked from inside the shell to print state. This is as close as it gets to a “standard”. This blog post does a good job explaining it. The configuration is a mess. The code is quite complex and handles a lot of strange git situations I wouldn’t have realized were important.
  3. bash-git-prompt is a different approach that has a bit more info on the state of the repo. As nice as it looks, I’m not going to use something that invokes a Python script every time bash needs to print a prompt.
  4. GIT Prompt uses colors to convey repo state, sets the terminal title, etc. It’s a very fancy prompt, but it’s overkill for my purposes. I do like how it displays non-zero exit codes though, and it’s got a nice configuration mode.

Screen Shot 2013-04-06 at 4.34.05 PM

I settled on option #2, the “stock” git-prompt.sh. It seems to work pretty well. The biggest problem is that Ubuntu 12.04 has an old version that doesn’t support working via PROMPT_COMMAND, so there’s an ugly workaround. Also gotta love the quoting. Anyway, screenshot and configuration.

GIT_PROMPT_VERSION=`sha1sum /etc/bash_completion.d/git`
if [ "$GIT_PROMPT_VERSION" = 'c52dd44066a21660c8830f8e6bd700893e2f7569  /etc/bash_completion.d/git' ]; then
    BAD_GIT_PROMPT=1
fi

if [ -n "$PS1" ]; then
  # Figure out what prompt character to use
  P='='
  if [ $UID == 0 ]; then
    P='#'
  fi

  # Set traditional prompt
  PS1="(\h) $P ";
  PS2="> "

  # Set up git prompting if available
  declare -f -F __git_ps1 > /dev/null
  if [ $? -a \! $BAD_GIT_PROMPT ]; then
    PROMPT_COMMAND='__git_ps1 "(\h" \)\ '$P'\  " %s"'
    GIT_PS1_SHOWCOLORHINTS=1
    GIT_PS1_SHOWDIRTYSTATE=1
    GIT_PS1_SHOWUNTRACKEDFILES=1
  fi
fi

I have some concerns about running any commands at all from inside a bash prompt. First it’s notably slow, particularly on a cold cache. Even warm it’s a few hundred milliseconds, and every extra GIT_ status thing I enable makes it slower. Worse, prompt commands do bad things if the command fails. Particularly a problem if you’re inside a remotely mounted filesystem that’s hung. I don’t know if bash is smart enough to timeout commands called when printing the prompt.

Update: this prompt setup is intolerably slow for big repos like libgit2 on a network filesystem mounted via SMB from a Linux server to a mac client. I’m talking 1000-1300ms per prompt, a noticeable pause. With no GIT_PS1 environment variables (just showing branch), the git prompt takes 25ms. Adding GIT_PS1_SHOWDIRTYSTATE adds an extra 100ms. GIT_PS1_SHOWUNTRACKEDFILES is the big culprit, adding an extra 1200ms or so. No surprise, the underlying command git ls-files --others --exclude-standard is making calls to getdirentries64() for every directory, also processing .gitignore files all up and down the tree. Not sure there’s any way to make that fast on a network file system. Maybe that’s why they went through the trouble to let you override the environment variable in the local git config.

Unrelated, but also useful; git-completion.bash which adds smart completion support for the git command. Seems to rely on the bash-completion addon to bash, although the script itself is distributed with git. In Mac Homebrew it’s a separate file; on Ubuntu it’s rolled together with git-prompt.sh. Apparently that’s an upstream change from a year ago.

GitHub pull requests are too heavyweight

GitHub is a marvel. But it’s a PITA to submit pull requests. It’s too heavyweight; in particular you’re required to log in to GitHub and make a fork. Here’s what you have to do:

  1. Log in or sign up to GitHub
  2. Fork the project
  3. Check out your fork
  4. Manually “git remote add upstream”
  5. Create a branch
  6. Make your changes and commit them to the branch
  7. Push your changes back to GitHub
  8. Submit a pull request
  9. (time passes, you want to submit another patch)
  10. Pull changes from upstream to your local repo
  11. Push your merging of those changes back to GitHub
  12. Go back to step 5 for next patch.

The thing that really gets me is if I want to make a one line patch to a repo, I’m committing to creating and maintaining a fork. The necessity that I remember to pull changes from upstream and commit them if I ever revisit that project is particularly onerous. In practice I find myself deleting my forks after my pull request is done.

I’d really like to be able to do all this without GitHub, just using git’s native pull request support. Ie, let me just check out a copy of the master project (read-only), then make my changes locally and use some combination of git pull-request and git format-patch to upload my pull request to GitHub. But now that I look at it, maybe those tools aren’t robust enough. Not sure.

Organizing all my git

I use git enough now that my repositories are getting a bit messy. I decided to centralize them all in one place so I can access them over the network. (You know, the distributed part of DVCS). There’s lots of options, I settled on just using a bunch of bare repositories on a host I can ssh to.

Alternatives I considered.. Dropbox is a good alternative for the central git repository but I’ve got my own server so I’m using that. The git:// protocol seems like unnecessary complication. As for hosting and web frontends.. GitHub is too expensive for my 10+ private repos,, charging per repo. Sites like repositoryhosting, gitorious, codeplane, and bitbucket have cheap or free options, but I don’t really need a centralized host since I’m mostly working alone. I could also have gotten fancy and installed something like gitolite to have a webapp front end, but that’s overkill for me now. Maybe I’ll set up gitweb at some point.

Here’s how I migrated my exisiting ad-hoc repos to one canonical gitrepos directory on a server. I found a lot of conflicting and incomplete info on how to do this, for instance these notes, this blog post, and this stackoverflow post. Correctly getting all branches into the new canonical repo and then patching up the config of the old ad-hoc repo is not straightforward. I’m not confident this is really correct, either, but it seems to work for simple things.

Find all the .git repos. Still have to hand-edit this list.
$ find ~ -type d -name .git | egrep -v '/d3|polymaps/'

Create a new bare repo in my new ~/gitrepos directory, based on code from ~/src/dotfiles.
$ cd ~/gitrepos
$ git clone --bare ~/src/dotfiles dotfiles
$ # is this a good idea? necessary?
$ # cd dotfiles; git remote rm origin

Change my old ad-hoc repo to consider this bare repo as its origin.
$ git remote add origin ~/gitrepos/dotfiles
$ git push
$ git branch --set-upstream master origin/master

That bit about pushing and then setting the upstream is 100% black magic for me, I have no idea what it does. It seems to be necessary to create the magic so that later “git status” will tell you if your local branch is ahead of the canonical copy in ~/gitrepos.  The push is necessary for some git config reason, even though there’s nothing to push. I find it confusing how git uses branches to track remote repos.

Also useful: “git remote -v” for seeing what remotes are configured, and “git branch -avv” for seeing more about git’s local view of various branches and remotes.

None of those examples above use a really remote repository, it’s all just Unix file paths. You can so name repositories like “nelson@example.com:~/gitrepos/dotfiles” and it will ssh to example.com and everything just works.

forking a branch on github

I’m trying to submit patches to https://github.com/mbostock/d3. Only what I want to patch is in the gh-pages branch, a special magic branch on github that is published as a website. Forking and modifying a branch is confusing if you don’t understand git. Here’s what works in my shell, after forking the repository:

# Get a copy of the forked repo
$ git clone git@github.com:NelsonMinar/d3.git
Cloning into d3...

# Link in the upstream repo you forked
$ cd d3
$ git remote add upstream https://github.com/mbostock/d3.git
$ git fetch upstream
From https://github.com/mbostock/d3
 * [new branch]      gh-pages   -> upstream/gh-pages
 * [new branch]      master     -> upstream/master
 * [new branch]      mbostock-master -> upstream/mbostock-master

# Create a local branch, somehow linked to the upstream's branch
$ git checkout -b gh-pages origin/gh-pages
Branch gh-pages set up to track remote branch gh-pages from origin.
Switched to a new branch 'gh-pages'

# Make your changes and commit them locally
$ ed README.txt
$ git commit -a -m testing

# Push to your fork on github
$ git push
To git@github.com:NelsonMinar/d3.git
   0d1679a..d351228  gh-pages -> gh-pages

The magic step is that checkout line. Other similar things like git branch gh-pages; git checkout origin/gh-pages don’t work and you can end up in weird states like “You are in ‘detached HEAD’ state.” I don’t really understand what all the working command is doing (I’ve got Matt to think for the code to copypasta) but I’m hopeful after reading the git docs on branches and remotes maybe it’ll make more sense.

using git on Windows via SMB

I keep my source code on a Linux machine, but I develop on Windows. The cross-platform thing is a nuisance. I mostly prefer to work in the Unix way, and make Windows cope.

msysgit seems to be the Windows git client of choice. (Cygwin is too foreign an environment). To make it play nicely with Unix systems:

  • core.autocrlf=false
    Don’t ever modify line endings, just accept what’s there. Every Windows editor I use can handle Unix line endings just fine.
  • core.filemode=false
    Don’t mess with file modes. Works around the problem that Samba doesn’t really handle Unix file modes right, particularly +x.  Avoids the problem of “old mode 100755 new mode 100644”.  This probably means you can’t meaningfully set file modes from Windows.
  • gui.encoding=utf-8
    Not strictly a Windows thing, but a good idea.

These can be set via the msysgit bash shell with “git config core.filemode false”. You can see your settings with “git config -l”. There’s something confusing I don’t understand about system/global/local settings that I’m ignoring.