Learn Git

Git is a famously powerful and famously confusing version control system used by software engineers everywhere. Increasingly, as other types of work begin to look more like software engineering (in my case network and systems engineering), git becomes useful for those folks as well. In that regard, here are some resources to learn git. I recommend you start at the top, get enough to work with, play with git by yourself, and return for the more advanced stuff when the basics don't cover your needs anymore.

  • Atlassian covers some good ways to install Git. I recommend the Homebrew method if you're on a Mac and use Homebrew. It'll make it easy to install and update Git as well as other software.
  • Git Essentials LiveLessons is a Safari Books Online video course for teaching the very beginnings of git. It's not a free resource, but it's a good one.
  • The Git Tutorial is a short text introduction to using git.
  • GitHub makes an interactive tutorial.
  • js.org has a very nice interactive tutorial on Git branches.

Once you have a decent workflow with git, you need to learn some of the theory behind it and the more in-depth commands it offers:

  • The Git User Manual is a relatively short introduction to some of git's features
  • Pro Git is a free online book for learning git that goes from beginner level to expert level. Very useful for learning the commands.
  • “Getting Git” by Scott Chacon is a great video explaining how git tracks content internally. A lot of git suddenly makes much more sense once you see it from the inside out.
  • Git For Ages 4 And Up is another really good video explaining git internals (though it's not perfect: questions interrupt the presenter, and it's cut short). As a bonus, I think everyone was required to dress like a hipster for it.

Git is such a flexible tool that there are multiple workflows possible for it. Different teams will choose different workflows, but here are some of the more popular ones:

Git Notes

Forking and Syncing with GitHub

Sometimes I need to make a change to a public repo I own (like my dotfiles) from my work laptop. I can't simply clone the repo and make the change because my work laptop doesn't have access to my personal logins so I don't have permissions to push (by design, not necessity). So, here's how to do a PR workflow

  • Work PC: In GitHub, fork the repo to my work GitHub account
  • Work PC: In the terminal, clone the repo
  • Work PC: In the terminal, make the change, commit, and push
  • Work PC: In GitHub, make a PR to the personal repo
  • Home PC: In GitHub, merge the PR
  • Work PC: In GitHub, sync the fork (button at the top)
  • Work PC: In the terminal: git pull to pull the merge commit

Many of these steps use GitHub's web UI. There's other ways to do parts of this with Git directly, but they're not as convenient for me.

Moving commits to a new branch

I try to work on new features in a branch, but sometimes I just work on master and need to move to different branches. Luckily, Stackoverflow has me covered:

git checkout -b newbranch # switch to a new branch
git branch -f master HEAD~3 # make master point to some older commit

Delete a local remote-tracking branch

From StackOverflow:

$ git branch -a
* master

$ git fetch origin --prune
From https://github.com/bbkane/warg
 - [deleted]         (none)     -> origin/bbkane/issue46
 - [deleted]         (none)     -> origin/searchFuncPtr

Git blame with Log Ranges

From Git Tips 1: Oldies but Goodies

git blame -L 28,43 path/to/file


git log -L28,43:gitbutler-ui/src/lib/vbranches/types.ts

See the post for more options, like looking for code that moved.