Merging GitHub pull requests from the command line

I just tested it, because I wasn’t sure.  As of 2018-12-09:

  • If you use git merge to merge a pull request (PR) from the command line, GitHub will detect that the PR’s commit(s) have been added to master, and will automatically mark the PR as “merged”.
  • If you instead use git rebase to move the PR branch onto master, GitHub will not automatically mark the PR as merged.

This makes sense, because rebase doesn’t actually modify the existing commit(s) in the PR.  Instead, it creates new commit(s) that make the same changes the PR’s commits would have made if merged.  So if you want to rebase or squash, do so from the Web interface.  (Or, alternatively, this tool and its corresponding blog post — although please note that I haven’t tried it myself.  Let me know if you do!)

I tried these with PRs in a single repo.  Please chime in if you have any experience with merging PRs from a fork into a parent.

(And one final note: I discovered the hard way that git rebase won’t preserve empty commits.  That is because it cares about the changes, so a commit that makes no changes isn’t of interest to rebase.)

vim: cleaning up mixed indents

Thanks to the wiki for this.  If you run across a file that mixes tabs and spaces (ewww!), set the tab settings the way you want (e.g., ts=4 sts=4 sw=4 et ai) and run

:retab

to convert all the tabs to the right number of spaces.  This takes tab stops into account, which :%s/^I/    /g won’t.

This replaces what I used to do, which was /^I s<Tab><Esc> followed by a whole lot of n.n.n.n.n.n.n.n. … .  One command is much better 🙂 .  I’m not even going to try to count the keystroke savings on my current project (pym, a preprocessor written in Python).

Vim: joining lines having continuation markers

This handy file-renaming script at Perl Monks has source code with red “+” marks marking wrapped lines. I pasted it into Vim and wanted to wrap those lines back to the way they should be. After a bit of fiddling, I got:

:g/^+/execute "norm 0x" | .-1,.j!

The `g/^+/’ finds the lines beginning with a “+”. Then the `execute “norm 0x”‘ deletes the “+” (“0” moves to beginning of line; “x” deletes), “|” marks the next command, and `.-1,.j!’ joins (“j”) the current line (“.”) with the previous line (“.-1”) without whitespace (“!”) added between the lines.

I leave it to you whether I have too much time on my hands.