Tag: github

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