Recently, I heard about a few online tutorial/classes about git/github. I’ve gone through some of these and wanted to quickly jot down some thoughts:

First, GitHub actually offers training classes! Just a few days ago I took their free online introductory class. It’s a 1-hour class that’s virtually hosted (through GoToMeeting). For the class I sat in on, two guys (Tim Berlund and Jordan McCullough) were running the show. It’s pretty well put together, where one person does live coding/commands and the other fields questions in near real-time from folks who send in their questions. It’s a bit difficult if you want to follow along with the same commands on your own computer, but they do a pretty good job of explaining things, so it’s not too hard to just watch what they’re doing and learn a thing or two along the way. What I really like about what they’ve done is that they’ve added office hours that occurs right after the webinar. During this time, you can ask them whatever question you like and they’re more than willing to delve in to slightly more complicated git/github scenarios and work through similar examples for you (again, through GoToMeeting).

Github also links to an in-browser tutorial for Git done by Code School. Given that it’s only meant to be a 15-minute lesson, the material is pretty basic (for anyone who is already used git/github a bit). But it’s neat to be a given a unix-like interface that doesn’t require any setup on your machine. This would be a great resource for anyone who’s just starting out and is completely new to git/github.

Code School also has a slightly more advanced Git course. They have a slightly gimmicky way of adding a you’re-a-secret-agent type of backstory to the lesson, but the actual content is decent. Personally, with online videos, I like having an option to control the playback speed. Code School doesn’t seem to provide that option, but you can download the videos to your computer, so you can find a player that supports faster playback speeds. Each of their lessons ends with a few questions, like a quiz. I like how they give you practical questions and you have to figure out what commands to run. So instead of phrasing the quiz question as ‘type git add to add files’, you get questions that are phrased like ‘you’d like to add the file you’ve just created to git’. The difference is a slight one, but it does seem to add just a touch more realism, which is appreciated. Unfortunately, only the first lesson is free. I haven’t ponied up the money to try out the rest of their Git course, but it looks like they also have some other interesting classes, so I may consider this in the future.

GitHub also offers a few video resources. I checked out the ones on advanced git, git notes, and fringe git and found them all pretty informative.

While going through these tutorials, here are some tips/handy shortcuts that I picked up along the way:

  • To add some color to git outputs
    git config --global color.ui true
  • To see the diffs in all the files you’ve staged so far (i.e., files you’ve added but haven’t committed yet).
    git diff --staged
  • A shortcut to visualize your tree/branches
    git config --global "log --graph --oneline --decorate --all"
  • In case you’re doing cross-platform work, then you might consider running this when you’re on Windows
    git config --global core.autocrlf true

    and this when you’re running on Mac/Linux

    git config --global core.autocrlf input

    The difference is that the first setting converts all CRLF line endings (the Windows default) to LF line endings (the Mac/Linux default) when you commit. When your checkout, the first settings converts all LF line endings to CRLF. So, locally, all files will have CRLF line endings, and all files in the git repo will have LF line endings.
    The second script only converts CRLF line endings to LF line endings on commit (but not on checkout). The git repo will all have LF line endings and, as long as you’re developing on a Mac/Linux, then the local repo will also have LF line endings. And, in the event that somehow a file creeps into your local repo with a CRLF line ending, the second setting will convert that to a LF line ending, and thus the git repo continues on having LF line endings only.

  • Because git notes are not pushed by default, you can set up a shortcut for pushing git notes across all namespaces up to GitHub.

    git config --global alias.pushnotes "\!sh -c 'git push \$1 refs/notes/*' -"
    git pushnotes origin

    Similarly, you can do this for fetching all the git notes on a remote repo

    git config --global alias.fetchnotes "\!sh -c 'git fetch \$1 refs/notes/*' -"
    git fetchnotes origin

    Or, with fetching, you can also just add a line in your .git/config file, so that fetching notes is part of the normal fetching process.

    [remote "origin"]
       fetch = +refs/notes/*:refs/notes/*
  • An interactive way to add only parts of your staged files and not the entire file

    git add . -p

    This steps through each diff in your staged files and asks if you want to include that ‘hunk’ (git’s term of a diff).
    You can use the -p flag with stash as well: git stash -p

  • A cool script that continually refreshes and shows a log of your git commands in real-time.
  • Another script to generate random changes, which can be useful when you’re testing out some of the git features but need to create some kind of check-in history.

Leave a Comment

Your email address will not be published. Required fields are marked *