Vimdiff and Vim to Compare Files

At the moment I’m working on a tricky project where two similar projects diverged. Very similar things happened to them both, but not quite the same things – and now we’re merging the codebases to give us as much common code as possible. All this simply serves to set the scene of exactly what I was doing spending a whole day with large code diffs – I had to look up a few things so I thought I’d capture them while I can remember. Continue reading

Hubot with Git Submodules

I love hubot and use one in a few different places. One thing I do find though is that I often want to edit or evolve those plugins, and it seems somehow unethical to just hardcode my changes into my own repo. Once I figured out how to wire together a forked repo as a submodule, it became much easier to work with hubots with external plugins, so I thought I’d share my recipe for that. Continue reading

Git: upstream is gone

I came across a git repo recently that output this message with every operation I did:

Your branch is based on 'origin/master', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)

I was delivering a workshop at the time so I kinda snarled at it and carried on with what I was doing, but later I looked up what is happening. This occurs when a branch is tracking a branch that the git repo doesn’t have any information about – the branches to be tracked aren’t in the local repo metadata.

In my case, it happened because I had created and then cloned an empty repo for training purposes – so origin/master didn’t actually exist yet! I added a quick commit-and-push to my script and hope that I won’t be upstaged by this change that came in with git 1.8.5.

Hopefully this post will help someone else to avoid being upstaged or irritated by this as well!

Announcing the Git Workbook

I’m very pleasedtitle_page to announce the immediate availability of my new book Git Workbook, costing $20 from LeanPub. This is a book that you “do” rather than “read”; it’s a series of chapters (30 ish so far) each covering one specific git skill.

Each chapter includes an explanation of the skill in question, followed by a hands-on exercise so that you can work through the skill yourself, and ends with a tickbox so you can keep track of how far through you are. It has quizzes, diagrams, mildly amusing stories, and as many other examples as I could think of that could help anyone to take in this technical topic and understand how to apply the techniques covered. Continue reading

Git Submodules for Dependent or Common Code

Submodules are one of the most powerful and most mistrusted features in git, at least in the web development part of the internet where I spend my time. I’ve seen them go horribly wrong, but I’ve also had teams adopt submodules and have their development process run much more smoothly as a result – so I thought I’d take a moment out of my day to write down the process (and the gotchas) of development with submodules. Continue reading

Video: Git Remotes and Tracking Branches

Here’s a little demo video that I put together to explain pushing/pulling with multiple remotes and how tracking branches make this easier. It’s one of the chapters from my “Git Adventures” talk, but it didn’t make it in to the talk in Amsterdam last week since we chose a different adventure that time – sharing it here in case it’s helpful to anyone else, and so I can find it later!

I also blogged about the tracking branches in a bit more detail if you’re interested.

Understanding Tracking Branches in Git

Here’s a topic that took me a while to understand in git, and now (I think!) I do, I thought I’d write it all down while I can remember!

Some branches in git (such as your origin/master branch) will usually track the remote branch that they are related to. But what if you want to create a relationship between local and remote branches? Or stop them from tracking? Here’s some pointers Continue reading

Colourless Git Output

I teach git and often have issues with bad projectors where you can’t see the colours. Recently I had a setup where even white on black was more or less invisible, but using black text on a white background worked okay. There’s lots of documentation on how to turn on colours in git but not so much about how to turn them off.

Try putting the following into .git/config:

[color]
    branch = false
    diff = false
    interactive = false
    status = false

I had expected to be able to set color.ui to false but that didn’t seem to make much difference, so I now use the settings above. I thought I’d drop it here in case anyone else is looking for the same thing.

Quick Switch Between Git Branches

Today’s little-known git feature (or maybe everyone knows but me? I only found this a few months ago) is for quickly switching between branches. Usually I would switch branches with:

git checkout [branchname]

However if you switch from one branch to another and want to switch back again (this happens when I’m reviewing changes and wondering if a bug is present on master as well), then you can do so by just doing:

git checkout -

Just a little timesaver in case it’s useful to anyone else – I know I’ve been using it quite a bit!

PHP and Git Training Course Dates

I’ve had a little flurry of enquiries about training lately, so I thought I’d mention the courses I have coming up, as especially the PHP ones are topics that I don’t run public classes on all that often. At the time of writing I have some space on all of these classes: Continue reading