when git can’t checkout a remote branch

Problem

Coworker has a workflow of:

  1. work on branch
  2. push branch and make PR of it
  3. delete local branch, checkout remote so that local is tracking remote
  4. carry on

except here’s what happened in the checkout stage:

user@host repo-name (master)$ git checkout issue-XXXXX-dummy-name-for-blogpost
 error: pathspec 'issue-XXXXX-dummy-name-for-blogpost' did not match any file(s) known to git.

It’s an old branch he’s trying to check out, but he just did the deletion step in this a few minutes ago. He does this all the time and he’s very experienced, so this was a bit of a pickle. I turned my rubber duckie over in my hands. We ran through some possibilities: doing a git fetch, trying it in a clean git clone (it worked fine), trying git-gc in the clone to see if it would break it, etc. Eventually, we turned to google.

Research

My search, yielded two stack overflow hits, and he told me about another.
They suggested checking git show-ref, and it we decided to diff the good and bad repo’s refs. The SO responses also turned up an explicit way to tell git to check out a remote branch locally and track it:

git fetch origin
git checkout -b test origin/test

His refs had something like the following in them:

bad repo:

user@host bad-repo-name (master)$ git show-ref
ddc955...0f61cb refs/remotes/experiment/issue-XXXXX-dummy-name-for-blogpost
86b183...ac388f refs/remotes/origin/issue-XXXXX-dummy-name-for-blogpost

good repo:

user@host good-repo-name (master)$ git show-ref
86b18399ad7cb01eeea74f5577c0a5dfe1ac388f refs/remotes/origin/issue-20198-remove-easy-cloud-accounting-copy

Solution

This led him to the realization that git must be doing some name-matching and hitting the first instance of the branch name. That ref line tells us that commit ddc955…0f61cb is ref’d as a branch with our name on a remote named ‘experiment’. The other line says that there is a different commit ref’d as a branch with our name on a remote named ‘origin’, which is what we want to check out.

Here’s the problem, and it was the aha moment: the ‘experiment’ remote no longer exists — this commit is old enough to have been used on a nascent form of this repo, when it was an experiment, moved from an existing svn repository. The issue is that the ‘experiment’ commit can’t be checked out, and git (reasonably) gives up at that point.

So he deleted the experiment branch and used the explicit form for checking out a branch from origin to track the remote. Problem solved.

Takeaway

For the future:

  • testing with a clean clone is really useful for determining if your problem is in your repo or everywhere
  • git show-refs is a reallllly useful tool for telling you all the things

agh c++

I come from the land of python, where the grass is green and the trees are leafy. I’m writing a game in C++ for fun, because I’ve never had to do serious work with C++, and so far… it seems like a nightmare-zone.

First, there’s the crufty syntax, full of useless symbols. That’s a known cost though, visible to any passer-by. Second, there’s type definitions — I have to figure out specific types just to hold outputs of functions, which I’m only going to pass to other functions. But there are advantages and disadvantages to declarative, strongly typed systems, and I knew about this already, so I can’t really complain. Then the final straw: there are no list, tuple, or map types. You think I should use the STL? You’re right — that’s precisely what I ought to do.

Except: the STL requires layer upon layer of confusing boilerplate, and in order to navigate it, you have to really know your C++ shit inside and out. Today, I wanted to remove some unwanted elements from a vector. Several StackOverflow question-reads later, I think the best route is to create a functor (loosely, an object wrapping a function) to use with an iterator to pass into a function to pass into another function. After all that, I have little knowledge of the big-O algorithms underlying these pieces of my code. I’ve also written a dozen lines for what I think of as ‘l.remove(e)’, and I’m wading through complex STL errors to figure out simple syntactical issues.

Worst of all: it doesn’t even work yet. ‘std::remove’ will remove elements equal to a given value, but doesn’t handle functors, while ‘std::remove_if’ can handle a functor, but messes up my iterator somehow so the vector doesn’t truncate.

Imagine a compilable and interpretable dynamically-typed (or at least type-inferred) language with minimal syntax and useful built-in types possessing relevant comprehensions. Now, imagine that it has bindings to popular open source game development libraries. Why can’t that be a thing?

I’m sure that 90%+ of my issues are coming from not having a sufficiently well-developed mental model of the C++ landscape, and if I knew my way around, I wouldn’t be having these problems, but I don’t. I didn’t expect to have to learn how to walk again when I’m already intimately familiar with C, with Python, and with reasonable program design. It’s not a different paradigm, it’s just that everything is harder here.

A different take on the situation is that the things that I’m annoyed by are showing me weaknesses in my own comprehension. Details I ought to be comfortable with are so commonly swept under the rug that I’ve forgotten they were even there, and now that I have to think about them, I’m more prepared to whine than solve the problems. So I’ll just keep on with it, I suppose, but there may yet be more whining.

Quick clever idea I saw

Someone at work just pasted in some code that was locking two tables for write, inserting all of one table’s data into another, then making a trigger to keep them in sync in the future after inserts, and then unlocking the tables.

Someone else suggested just making the trigger first, and then replacing all of the data from the first table into the new one. Using replace means that some of the data may be double-copied, but there’s no table-level write locks used — pretty cool.

Also, we’ve been talking about hypergraphs, which are a little confusing. They’re graphs, but instead of each vertex having multiple edges and each edge running between two vertices, each vertex can have multiple edges and each edge can have more than two vertices! I ran into them once before, and still don’t quite understand how that situation even was a hypergraph.

Rigour vs Just Do It

I’m reading The Mythical Man Month, and I also happened to read this post on just getting something started this morning. I’ve got two (conflicting?) messages in my head at the moment:

From the Mythical Man Month, I’m hearing about how much planning used to go into development and testing of software systems. That sort of rigour just doesn’t seem to be present any more, and I am taking a desire away from the book to be a little bit more careful and systematic and thoughtful when approaching a new project. Kind of like that (perhaps apocryphal) Einstein quote about solving a problem in an hour: “If I had an hour to solve a problem I’d spend 55 minutes thinking about the problem and 5 minutes thinking about solutions.” It’s allegedly beneficial to sit down and think before you start doing.

Against that, from the Lean Startup and Fail Fast sort of camp, I have the suggestion to just get something out there. Write anything down, acknowledging that it’s awful, just to get started. Step 2 is easier, and iteration is what drives progress. You won’t know most of the problem until you really dive into solving it. That kind of thing.

These both seem right, but they also seem incompatible. There’s probably a middle road — I wonder whether it’s best to think out how to find it, or to just start trying things and hash something out?

Sickness sucks.

I spent the last week sick with a bad flu. I always imagine that getting sick for a big block of time will be great for reading or watching TV or doing some kind of online course or something, but in that imagination I fail to account for the following issues of the flu:

  • flu-people have no motivation for anything, even peeing or hydrating or breathing
  • flu-people are in constant discomfort and just want to close their eyes
  • flu-people can’t focus on stuff, even if they want to
  • flu-people smell and are sticky and sweaty and ick
  • flu-people think pretty slowly, and mess up some pretty simple logic

So my mighty plans were foiled! But now that I’m getting past it I feel renewed vigour and just feeling ‘normal’ feels comparatively great.

So what do I do now? It’s that perennial problem – I might need a philosophical response to it that just kills the whole question. Being interested in everything to the point that nothing can hold my attention for more than 48 hours is wonderful in its way, but it has made me into a massive dilettante.

I think I found at some earlier point that I find motivation in seeing other people do cool stuff, which only happens when I feed more input into my infohoppers – more commitment to consuming lots of diverse media sounds good. Also, easing barriers to making stuff.

Anyway, I’m glad to be back in the waking world. Next stop: not coughing and sneezing on everything. (there may be some time before we reach that stop)