The reason your `sed` line isn't working is (I believe) because when the `git` process fails, it breaks the pipe to `sed` and causes it to not process the empty line.  We can take advantage of the fact that the `git` process is failing and just use that as the trigger to print 0:

```bash
fork_master_distance = $(shell git rev-list --count HEAD ^"origin/master" 2>/dev/null || echo 0)
```