How to view diffs of images in a GitHub repo – 054

GitHub offers 3 ways for you to diff your images. For example, this commit diff shows how I checked in an image and then changed the image completely in the next commit.

commit diff showing how the octocat as Clark Kent has changed into the octocat as Superman w a 'G' logo

At the bottom of the image, you’ll see the options for 2-up, Swipe, and Onion Skin.

2-up

The default view is the 2-up, which shows the images before and after side-by-side.

Swipe

Swipe allows you to do more of a pixel-by-pixel comparison by allowing you to slide a splitter back and forth over the image.

half Clark Kent image and half Superman-octo image

Onion Skin

Onion skin allows you to pick up on subtle changes you might have otherwise missed. Although there’s nothing subtle with the image I picked Smile

animated gif showing a slow change from octo-Kent to octo-Superman

Today’s tip of the day images are brought to you by https://octodex.github.com/. And thanks to the Help Documentation for clarifying when to use Onion Skin versus Swipe!

How to find and use different Octocat images from the Octodex – 053

GitHub users love stickers. Especially at conferences. It’s hard playing Oprah. I’ve never given out so many stickers in my life!

There’s the standard Octocat image, but did you know we have an Octodex?

https://octodex.github.com

If you’ve got questions about what you can and cannot do with your new favorite Octocats, check out our Octodex FAQ for some answers.

My favorite (of course) is Red Polo.

the Red Polo

How to press ‘y’ to navigate to the permalink for a file’s exact commit ID on GitHub.com – 052

Suppose you had a question about the contents of a file at an exact moment in time (or in git-speak: at an exact commit in time). If you were to visit the repo and navigate directly either to a file or the line in question in a file, e.g. https://github.com/saraford/your-moment-of-github-zen/blob/master/main.js#L74 showing the line

mainWindow.webContents.openDevTools();

you might forget or not even realize (like me) that you’re copying the link for the latest version of that file on master (or in git-speak: the version of the file at the current head of master).

In other words, if someone were to come along and make a change to this file, your link to this line of code at the latest commit on master might be a link to a totally different line of code instead of the openDevTools() link.

Press the `y` key and you’ll see that the page seems to refresh. Well, yes and no. The page has updated, but look at the URL now.

https://github.com/saraford/your-moment-of-github-zen/blob/f06f035cfed7c0ea05db8bd3cc25b22c43cea6d7/main.js#L74

now you got the permalink to that exact line of code!

This shortcut is the functional equivalent of clicking Code – Commit – Browse the repository at this point in the history – clicking the file (e.g. main.js) – and then clicking the line number.

This shortcut works for any branch name, specific commit SHAs, and tags, according to the docs. E.g. suppose you were looking at main.js on a branch called windows-fix located at https://github.com/saraford-tips/your-moment-of-github-zen/blob/windows-fix/main.js and you pressed the `y` key. The URL would change to https://github.com/saraford-tips/your-moment-of-github-zen/blob/811aacbd492044c8a02536129edf42862d0a593d/main.js

I hate not having a photo to go alongside a tip, so here’s a picture of a Great Dane next to a small (terrier?) dog, aka how I feel standing next to tall people.

Great Dane standing next to small dog

photo taken from https://flic.kr/p/b4RGX8

How to view the name and email that is associated with a commit on GitHub via the web browser – 051

Suppose you want to verify your email in your Git logs hosted on GitHub without pulling down the repository.

Navigate to the desired commit (via Code tab – Commits link – Commit)

commit displayed on github

Now in the URL shown in your web browser, add the extension .patch and you’ll see the name and email from your .gitconfig.

printout from a format-patch displayed in plain text

btw, in case you want to know what’s going on, this is actually the git format-patch command, where GitHub is displaying the output.

Since the commit ID is 32473a3, we can do

$ git format-patch 32473a3~1..32473a3

git format-patch 32473a3~1..32473a3

to get the same result in the command line.

showing generated patch file from command line

How to hide your email address in your Git commits but still get contributions to show up on your GitHub profile – 050

I have good news and bad news. Let’s start with the good news.

If you want to get credit for your commits, but don’t want to expose your GitHub email address in the commit logs (have you checked the logs? why haven’t you checked the logs*?), here are the steps you can take. 

contributions graph on GitHub profile

First, in GitHub go to Settings – Email – Keep my email address private

Keep my email address private checkbox

You’ll notice a new email saraford-tips@users.noreply.github.com for you to use for your Git commits.

Next, you’ll need to update Git to use this new noreply email instead of your real one. You can do this either from the command line or from GitHub Desktop.

From the command line, provided that you want to change your email address globally across all repos, you’ll simply do

$ git config –global user.email “your-username@users.noreply.github.com”

and then to verify, type

$ git config –global user.email

for example

git bash showing --global user.email changed

Or if you want to use GitHub Desktop, it’s just at Options – Configure Git which will do the same as the –global flag, hence the red circle around the global gitconfig message.

Configure git username and email address

You can read more in the GitHub Documentation for keeping your email address private, e.g. how to change only a specific repo, etc.

And now for the bad news.

This change will only apply moving forward. If you’ve been using your personal email address in previous Git commits, you’ll need to do some work to scrub the logs (where possible). Check out the GitHub Documentation for changing author info.

*My favorite all-time scary movie is the 1979 version of When a Stranger Calls. Well, not the entire movie, but just the first 15 minutes. And I don’t think it holds up anymore with smart phones being the norm. But wow, that was something scary! And yeah, you should check the logs… just to make sure you don’t have your email address committed that you don’t want others to see. 

How to use Git.io to shorten GitHub URLs and create vanity URLs – 049

Suppose you want to shorten the URL to a particular location on GitHub. Or perhaps you want to create a vanity URL that goes directly to your GitHub profile, e.g. https://git.io/saraford. You can use Git.io: GitHub URL Shortener.

To shorten a URL, open your favorite command prompt (via Git Shell) and type in

$  curl -i https://git.io -F "url=https://github.com/saraford/your-moment-of-github-zen/issues"

in the response, you’ll see your shorten URL!

Location: https://git.io/vMdeF

To create a vanity URL for your GitHub profile,

$ curl -i https://git.io -F "url=https://github.com/saraford" -F "code=saraford"

in the response, you’ll see a new way to refer to your GitHub profile!

Location: https://git.io/saraford

How to add a license to a repo (and have it be recognized) for an existing GitHub repo – 048

In yesterday’s tip, you saw how to select a license when you create a new project. Today’s tip is about how to get that license picker back for an existing repo.

Since licensing is done based on the content of a file named license in your repo, instead of metadata about the GitHub repository that lives alongside the repo, first, you’ll want to create a new file in your repo.

Create new file button 

Next, type in License and over to the right, the license dropdown button (re)appears. You can call the file license, license.md, LICENSE, or LICENSE.MD, as long as the filename is “license”

image

When you select a license, for example the MIT License,

Choose a License: MIT License

and you’ll see that the license text is inserted and some boilerplate information, like copyright year and name, are inserted.

MIT license showing copyright year and full username

Now when you commit this file (and wait a minute or so), you’ll see that GitHub now displays the license name at the top of the repo.

MIT license displayed at top of repo above language bar

Suppose you didn’t choose a license via the dropdown picker (either on /new or in the method described above). Suppose you’ve previously pushed a license file up to GitHub at some prior point.

GitHub uses an open source project called Licensee to do license detection, i.e. compare the license file to the list of licenses coming from the Choose a License website. According to the GitHub blog, “Licensee is the same code we use to provide the Licenses API and understand how repositories on GitHub are licensed.”

If you want to contribute to licensee, there’s a contributing guide in the repo. If you’re looking to add a new license that can be detected, you’ll want to check out the choose a license repo.