Some git / magit / github tricks11 Mar 2015
Of course, I mean illusions not tricks.
Illusion 1: jump to a magit repository
This is just a copy-paste of the code from this post by Iqbal Ansari.
(setq magit-repo-dirs (mapcar (lambda (dir) (substring dir 0 -1)) (cl-remove-if-not (lambda (project) (unless (file-remote-p project) (file-directory-p (concat project "/.git/")))) (projectile-relevant-known-projects))))
Basically it's just taking
projectile's record of known projects, and then filtering it by whether
that project has
.git in its root.
To get a selection of repositories, call with C-u M-x
And don't forget to choose
(setq magit-completing-read-function 'magit-ido-completing-read)
And here's how I use this in a dispatch:
(defhydra hydra-helm (:color blue) "helm" ("f" projectile-find-file "file") ("w" helm-org-wiki "wiki") ("g" (let ((current-prefix-arg 4)) (call-interactively #'magit-status)) "git") ("l" helm-locate "locate") ("q" nil "quit")) (global-set-key "κ" 'hydra-helm/body)
If you're wondering what the letter in
global-set-key is, it's the Greek letter
(see the post on my Xmodmap setup).
Illusion 2: quickly get Github pull requests on your system
I learned this from some HN post that I can't find now. Basically, you have to open
.git/config file and find the following contents:
[remote "origin"] url = firstname.lastname@example.org:abo-abo/hydra.git fetch = +refs/heads/*:refs/remotes/origin/*
Then, modify it by adding one line (same for all repositories):
[remote "origin"] url = email@example.com:abo-abo/hydra.git fetch = +refs/heads/*:refs/remotes/origin/* fetch = +refs/pull/*/head:refs/pull/origin/*
Now, if you issue:
git fetch --all
You can operate on your pull requests like so:
git merge refs/pull/origin/20
20 is the issue number. And after merging I finally get access to
all that jazz to see what the change is actually about. Before I learned this, I had to manually
add remotes with
magit-add-remote. And even before that, I was just clicking the merge button
after thoughtfully browsing the diff in Firefox. Trust me,
ediff is orders of magnitude better.
Illusion 3: edit a Github wiki in Emacs
Of course, I was always editing it in Emacs with It's All Text Firefox plugin. But when I wanted to add an image, I actually read the manual and found out that you can simply clone the wiki:
git clone https://github.com/abo-abo/hydra.wiki.git
Or with the ssh style, in order to not type the user name and password on pushing:
git clone firstname.lastname@example.org:abo-abo/hydra.wiki.git
By the way, today I've made a very large overhaul of hydra's README.md. So if you wanted to start writing your own hydras, but were hesitant because of the lack of documentation, now is the time to start.
If you figure out something that you think is worth documenting, you can immediately leave it on the wiki. By the way, here's the syntax for including an image, if you were wondering:
You upload a file simply by adding it to the repository. Look Ma, no Imgur!
This is actually an issue that I ran into, when I was less experienced. I included some one megabyte
gifs in the
lispy repository to refer to them in
README.md. Just a few of them resulted in a
very uncomfortable cloning time, which is an issue for Travis CI and, you know, humans. Finally, I
had to resort to bfg-repo-cleaner to remove the gifs
from the repo history. It could all be avoided if I just posted all images on the wiki and linked to
I hope that you find these illusions useful to make you a better Emacs magician. Happy hacking!