
Github is an important part of the life of a modern developer: it has become the standard for hosting open source projects. At 2GIS, we use GitHab to develop web-based projects and host open source projects.
Although most of us use the service almost every day, not everyone knows that he has a lot of chips to help facilitate work or routine operations. For example, retrieving a public key from a URL; tracking which sites users come to the repository from; correct sharing of links to files that live in the githab repositories; hotkeys and the like. The purpose of this article is to talk about non-obvious things and, in general, what will make your work with the github more productive and more fun (I will not consider working here with the github API, as this topic deserves a separate article).
Content
')
URL tricks
Github's philosophy is to be simple, but at the same time a very flexible tool. It is for this reason that many features are not available from the user interface, but are accessible via URL parameters.
Access to public keys
If you set up ssh access for colleagues who have an account on a githaba, the easiest way to do this is with public keys obtained directly from Github via the URL: https://github.com/<user_name>.keys (for example,
https: / /github.com/defunkt.keys ). If you have CI processes configured using this feature, you will always have the actual public keys.
Access to diffs and patches
If you add
.diff
or
.patch
to the end of the URL with a commit or pull request, you can get this output in the unix-utilities format diff or patch (for example, using a URL in this format
https://github.com/tars/ tars / commit / 07902a956da92e6a616a69d3b3f0f9276f0c13fe.diff - note the “.diff” at the end). Sometimes it is convenient to receive a set of changes in this way without departing from the cash register and send it to Slack or by email.
Sharing URL links to files in repositories
Here at first glance, everything is simple: copied the link to the file from the address bar of the browser, pasted where necessary. But, due to the dynamic nature of projects, commits are constantly added to the wizard, the contents of the file may change in the future or the file may be completely removed, so the usual copying of the browser’s address bar does not work here. To get a permanent link to the current version of the file (the
permanent link is what Github calls them), you must use a hash commit instead of the name of the branch in the URL. Yes, this is rather inconvenient, so the guys from github made a hotkey. Click "y" when viewing the file - the URL in the browser will be changed to permanent link.
Exclude whitespace characters when viewing diff
Add
?w=1
to the URL when viewing the difference of files, and if the differences were only in the spaces, it will no longer distract attention:

Highlighting a specific code block
When viewing a file, you can click on any of its lines and send someone a link to the specified location. You can select a rowset by adding the last row number in the URL after the line number using the minus sign, like this (note the L30-L32 at the end of the URL):
https://github.com/torvalds/linux/blob/9256d5a308c95a50c6e85d682492ae1f86a70f9b /include/uapi/linux/netfilter_bridge/ebt_among.h#L30-L32Comparing revisions of branches in the repository
When creating a pull request, you can immediately see what changes will fall into the target branch as a result of the merger. But there is an unobvious possibility of a branch comparison page: we can see all changes in a branch in a certain time, for example, in two weeks -
https://github.com/github/linguist/compare/master@%7B2week%7D...master . Sometimes it is useful to bookmark the comparison page in the browser and, if something goes wrong, quickly check what has been changed in the code, for example, in the last 24 hours (“master @ {1day} ... master). Under the hood of this feature, the standard git diff is used, so any time format that is perceived by git can be used. For more information on comparing branches, commits, and the like, see the
documentation .
Hotkeys
Personally, I am a big fan of hotkeys: they save time when performing standard actions and develop motor skills in children. Github has a lot of hotkeys, talk about the most useful ones.
Activation of fuzzy file search
If you press "t" when viewing the repository, a file search string will appear in which you can enter part of the path and select the desired file, saving minutes of wandering around the repository in the search.
Quick jump to a specific line in the file
Press "
l
" when viewing the file - a small window will appear to enter the line number.
Quick jumps to Github sections
These combinations are easy to remember: they begin with the prefix “g” (go), and the letter following it indicates the destination. gp is the transition to the list of pull requests, gi is the list of issues, gn is the notification page, and so on.
This list of hot keys is far from complete. To see all available hotkeys, click "?".
Tickets and pull requests
Ticket (issues) and pull-requests are invariable assistants in project management. Github provides many tools for working with them. You can use the tagging system and each ticket or pull request to affix the corresponding attributes, for example, feature, bug, documentation. You can also create milestones and specify on which ticket in which version the work will be performed. And there are some fun and useful tricks.
Auto-close issues using commits
If the text of the commit that falls into the main repository branch contains the words fix / resolve / close in different
variations and the ticket number after the “#” symbol, then the ticket with the corresponding number will be closed.
That is, a commit with this message:
$ git commit -m "Fix screwup, fixes #12"
will lead to this result:

Search for your favorite pull requests and tickets
This feature appeared relatively recently, when githab added reactions to comments. Now sorting can take into account the amount of emoji in the reactions. Accordingly, the type of emoji for sorting can be selected in the "Sort" menu:

Github markdown
The githaba uses a superset of markdown markup, which is used in comments and markdown files. With it, you can cross-reference between repositories or issues, create to-do lists, and highlight code.
Cross links
If when creating a ticket (issue) you need to mention another ticket, you can enter the “#” sign - a menu will appear from which you can select the required ticket; You can also write the ticket number yourself. When you save a comment with a link, the corresponding message will appear on the page of the mentioned ticket. If you mentioned another ticket from a private repository, the reference will be visible only to those who have access to this repository. In this case, you can make a link not only to the issue, but also to a specific commit, simply by specifying its hash - Github will automatically turn it into the correct link.
Syntax highlighting
To highlight a piece of code in your markdown markup, enter the name of the language after the triple back quote before the code block and the triple back quote at the end of the block:
```javascript function fancyAlert(arg) { if(arg) { $.facebox({div:'#foo'}) } } ```
To-do lists
The syntax for the to-do list is:
- [x] @mentions, #refs, [links]() - [x] list syntax required (any unordered or ordered list supported) - [x] this is a complete item - [ ] this is an incomplete item
When you save a comment with a list, it turns into a full list of tasks with checkboxes that can be marked (the corresponding [x] appears in the markdown markup automatically). Here is a good example of working with lists:
https://github.com/neovim/neovim/pull/243In general, be sure to check out
Github flavored markdown help - there are a couple of interesting tricks there.
Account
Two-factor authentication and security
There is nothing special to discuss here - just turn it on if you have not done it yet. This option is located in
Settings -> Security . By the way, there you can see the entire history of actions related to account security (a list of past sessions, ip-addresses, etc.).
Binding multiple email addresses to one account
If you use several addresses for work and personal correspondence, it may be convenient for you to distinguish between them at the git level, making commits to work projects with one email, and home for others. You can have a special box for all communications on the githaba. In all cases, a problem arises: service metrics will not accept commits with a mailbox other than the one from which the registration occurred. To avoid this, specify all email addresses that will be associated with your profile (
Settings -> Emails ). Keep in mind that updating information will take some time.
Addition from
aivus :
If you confirm these emails, then with their help you will be able to access your account (password recovery). If you want to simply associate an email with your account without a password recovery feature, simply do not confirm this box. Support githab advised to do so.
Saved replies
This feature is especially useful for those who often write comments of the same type to pull-requests or tickets. For example, that the pull request must comply with the rules defined in contributing.md. You can save a set of answers and quickly insert them through the Github editor menu:

The page for adding answers is here:
Settings -> Saved replies .
Mentions
This popular function in mechanics is similar to mentions on a desktop or on Twitter. When creating a comment, enter the “@” symbol and immediately after it the user’s nickname. The mentioned user will appear
on the alert page with a corresponding link to the ticket or pull-request in which he was mentioned.
Mentions are available not only for a specific user, but also for a group of users in an organization. In this case, after the "@" you must enter the name of the organization and through the slash the name of the command - for example, @ 2gis / mamonts. Adding a new command is available through the Teams tab on the main page of the organization.
Responses to Github Email Alerts
If email alerts are enabled in your settings, you can participate in discussions on the githaba without leaving your email client. If you respond to an email, then a comment will be created on your githaba on behalf of the corresponding ticket or pull request with the contents of your sent email.
Subscribe to public user activity
If you are interested in a particular user on Github, you can follow it (the “Follow” button on the user profile page) and then see its public activity (commits, comments, etc.) in the general list on the main page of the site. The main page can only show a slice for the last three days, so if you do not want to skip all user activity, you will need rss feeds that you can subscribe to using the link like https://github.com/<user_name>.atom. In the same way, you can subscribe to all public activities of the organization (for example,
https://github.com/2gis.atom ).
Work with repositories
Github service directories and files
If there is a readme file in the root of your project, its contents will be displayed under the file list. This is known to many. But not everyone knows that if you create a file contributing.md with recommendations for improving the project, a link to it will be available on the page for creating a pull request or opening a ticket:

After closing code.google.com, many projects moved to Github. In this regard, many
requests for improving the service fell on the githab (yes, this is just my guesswork, but it is possible that this event served as a catalyst to some extent). One of the requests was to create templates when opening tickets. Github recently
implemented this feature.
Create a file called ISSUE_TEMPLATE inside the project root, and its contents will be automatically inserted into the input field when you open a new ticket. The same works for pull requests, in this case the file should be called PULL_REQUEST_TEMPLATE. Files can be in markdown format.
Here is an example of a template from the React repository -
https://github.com/facebook/react/blob/20bcabb1ea4cf492ade240bd6915b4bd44f04895/.github/ISSUE_TEMPLATE.md . If you try to open a ticket in their repository, the text entry field will already be filled with useful information:

To avoid heavily cluttering the project root with service files, you can create a .github / directory and put all the files associated with Github in there. All functions associated with these files will work as before.
Programming language statistics
The main page of the repository in the form of a color bar displays the statistics of the languages ​​used in this repository. If you click on it, the percentage will be displayed:

If you use some big js framework in your project and do not want it to have 70% of your favorite Go / Python / Java / Ruby in the repository statistics, create the vendors directory and put all dependencies there that should not be taken into account github statistics system. Or check the availability of the file or directory that you want to get rid of in the statistical data
here - it is quite possible that you don’t need to do anything
Yes, if the languages ​​in the project are defined not in the right way, then in this case it is worth looking at
linguist . Linguist is a ruby ​​library with which the githab collects statistics on the languages ​​used. The project readme describes various ways to override the specified file.
Repository metrics
Github provides many metrics to track the work happening in the repository. Appropriate monitoring tools are on the tabs Pulse and Graph. Pulse shows what happened in the repository in a certain period of time. In the Graph section, various indicators are shown in the form of graphs. Owners of repositories in the Graph tab also have a sub-item Traffic. By and large, this is a mini google analytics for the repository: it can track how many users were in your repository and where they came from.
Creating a new repository
When creating a repository, you can immediately choose which gitignore file is needed, what kind of license the project will have and whether you need a blank for the readme file. So you will save some time at the initial stage of project preparation:

If your project type is not in the gitignore list, then you should improve this situation and suggest a pull-request to the
gitignore github repository.
Code search
Another unobvious github opportunity is advanced code search in all repositories:
https://github.com/search :

As in any serious search service, you can go to the
advanced search page and specify the specifying parameters: for example, user name, creation date, language in which the code is written.
When searching, there are
restrictions that should be taken into account if you are running a project on a githaba and you want the service to index your code (or, conversely, if you do not want): only the main repository branch is indexed (usually the master); only those files that are less than 384 KB are indexed; Only those repositories with less than 500,000 files are indexed.
Command line and Github
Hub
Hub is a console utility from the creators of the githab (git + hub = github), the purpose of which is to facilitate the use of the service from the shell. In essence, the hub wraps the standard git and provides additional commands for working with repositories, pull requests and tickets.
This is how you can clone the repository:
$ hub clone github/hub
Make a fork:
$ hub fork
Open pull request:
$ hub pull-request
The authors of the utility advise, after installation, to make an alias on the hub when calling git (alias git = hub), since the hub commands do not conflict with the standard git commands.
More information on working with the utility can be found in man or on
the project website .
Pull-Requests already in your repository
An interesting point that few people know about. When you create a pull-request, all changes contained in it automatically fall into your repository, since pull-request is, in general, a special branch. Because of this feature, a githab can show changes in a pull request, even if the original fork has been removed. So you always have access to them. To make changes from a pull request to a new branch (new_branch), you need to run the command:
$ git fetch origin pull/<pr_num>/head:new_branch
where <pr_num> is the pull request number from the URL.
User scripts
User script is a custom JavaScript code that changes a specific site / web application, changing its appearance and / or adding new features. There are quite a
few scripts designed to work with githubs. There are a lot of outdated scripts in the catalog, but among them are quite modern and useful.
Github commit whitespace
Github Commit Whitespace simply adds a link to the comparison page, with which you can quickly exclude modified whitespace characters from diff:

Github News Feed Filter
Github News Feed Filter will be especially useful to those who monitor (watch) many active repositories / users. This script adds a filter to the main page with the event ribbon that allows you to display only the interesting activity:

Github vandalism
Gitfiti
Yes, this is not about effective work, but about the things that resourceful developers use for fun. Namely, here are the boxes showing your contribution throughout the year - contribution graph:

By manipulating the git-repository, adding commits to certain dates in a certain amount, you can slightly diversify the diagram. For example, like this:

Of course, nobody does it by hand. There is a great
gitfiti chart generator for this, which has pre-installed image templates and the ability to use your own.
Replacing the author of a commit
In git there is the possibility of correcting the author of a commit through
$ git commit
As a result, the commit in the githaba will be displayed with a new author and his avatar:

Nothing wrong with that, especially since Github
added GPG-signature commit author authentication in April. If you see the word “verified” next to the commit, then the author of the commit is this person, and not someone else:

Additional Github Resources
Repository ratings
The source of new tools and libraries is the page
https://github.com/explore . Here you can find different collections of repositories, repositories that have been added to favorites by the people you are subscribed to, and, of course, the most popular repositories
lately .
Service status
Quite rarely, but it happens that the githab is unstable. The main resource where you can find out what went wrong -
https://status.github.com/ . There you can find different metrics reflecting the state of health of the githaba and all alerts about interruptions in the service.
Github pages
Github can host static sites. This is very convenient if you need to make web-documentation for your project or promotional website. Many use githabs for personal blogging. In the simplest case, it is enough to create a gh-pages branch in your githab repository with index.html inside. The page will be accessible to the address in the following format: http (s): //.imtqy.com/ <project_name> - for example,
http://2gis.imtqy.com/makeup/ . More information can be found in the
documentation .
Gist
Gist is a git-repository without directory support. It is usually used to store pieces of code and drafts; There you can also find full
tutorials and articles .
We can say that this is such a light version of the githab for your notes of any nature, with comments, versioning and the ability to create an unlimited number of secret records that will be available to other users only by direct link .Gist can be used on third-party resources. Many use it to highlight the syntax of code snippets on static blogs or on Medium. To get the gist script code that can be embedded on the page, you must select Embed from the menu for selecting the type of URL to the repository:
Dotfiles
On http://dotfiles.imtqy.com/ you can find high-quality collections of Unix-system settings for every taste.Octodex
But at https://octodex.github.com/ there are just a lot of oktokots. Nothing more. KDPV we took from there.useful links
Github provides so many possibilities, and describing them all in one article is a serious task. Nevertheless, I hope that this material will serve as a good source of new knowledge and inspire you to explore Github further.Finally, here are some of the most interesting resources that will help you on this journey:— the Steroidtocat by James Kang