Difference between revisions of "Magit"

From WikEmacs
Jump to: navigation, search
m (Transient, the Magit pop-up system)
(Helpful keybindings: add file dispatch)
Line 21: Line 21:
  
 
== Helpful keybindings ==
 
== Helpful keybindings ==
 +
 +
=== Starting Magit ===
  
 
* {{Command|magit-status}} is the main entry point to Magit. The author recommends [[Key_Bindings|binding]] this command to "a key of your choice". {{Keys|C-x g}} is a common choice:
 
* {{Command|magit-status}} is the main entry point to Magit. The author recommends [[Key_Bindings|binding]] this command to "a key of your choice". {{Keys|C-x g}} is a common choice:
 
{{Snippet|(global-set-key (kbd "C-x g") 'magit-status)}}
 
{{Snippet|(global-set-key (kbd "C-x g") 'magit-status)}}
 +
  
 
The [https://github.com/magit/magit official Magit documentation] is excellent and should be consulted for further information.
 
The [https://github.com/magit/magit official Magit documentation] is excellent and should be consulted for further information.
 +
 +
=== File dispatch ===
 +
 +
{{Command|magit-file-dispatch}}, bound to {{Keys|C-c C-g}}, lists commands that concern the file you are in: list the commits that changed it, navigate in history, call blame, etc.
  
 
== Forge: interface to Github, Gitlab and other Git forges ==
 
== Forge: interface to Github, Gitlab and other Git forges ==

Revision as of 06:51, 17 June 2019

Magit
Description Git integration for Emacs
Author Marius Vollmer
Maintainer Jonas Bernoulli
Source https://github.com/magit/magit

Magit is an Emacs mode for working with Git repositories. It provides a convenient interface for the most common Git operations.

Basic setup

Install Magit from MELPA:

   package-install RET magit RET

And require it in your dotfile:

(require 'magit)

Helpful keybindings

Starting Magit

  • M-x magit-status is the main entry point to Magit. The author recommends binding this command to "a key of your choice". [C-x g] is a common choice:
(global-set-key (kbd "C-x g") 'magit-status)


The official Magit documentation is excellent and should be consulted for further information.

File dispatch

M-x magit-file-dispatch, bound to [C-c C-g], lists commands that concern the file you are in: list the commits that changed it, navigate in history, call blame, etc.

Forge: interface to Github, Gitlab and other Git forges

Forge, released in december 2018, allows you to work with Git forges—such as Github and Gitlab—from the comfort of Magit and the rest of Emacs. We can manage branches, pull requests and issues, these two being called "topics" in the documentation.

Forge can be seen as the successor of 'magithub', which was limited to Github, and 'magit-gh-pulls'.

See the announcement on Magit's website: https://emacsair.me/2018/12/19/forge-0.1/ and its manual.


Loading Magit doesn’t cause Forge to be loaded automatically. Adding something like this to your init file takes care of this:

(with-eval-after-load 'magit
  (require 'forge))

Or if you use use-package:

(use-package forge
  :after magit)

Common Customization

Change magit diff colors

If you want more common colors (green and red), instead of psyche highlighting:

The following way seems not working with recent Magit.

(eval-after-load 'magit
 '(progn
     (set-face-foreground 'magit-diff-add "green3")
     (set-face-foreground 'magit-diff-del "red3")
     (unless window-system
       (set-face-background 'magit-item-highlight "black"))))

Try this with recent Magit.

(custom-set-faces
   ;; custom-set-faces was added by Custom.
   ;; If you edit it by hand, you could mess it up, so be careful.
   ;; Your init file should contain only one such instance.
   ;; If there is more than one, they won't work right.
   '(magit-diff-added ((t (:background "black" :foreground "green3"))))
   '(magit-diff-removed ((t (:background "black" :foreground "red3")))))

Use ido to checkout branches

(setq magit-completing-read-function 'magit-ido-completing-read)


Transient, the Magit pop-up system

Transient is, since february 2019, an independent package that powers the famous Magit pop-up system. It superseedes magit-pop-up.

See the release announcement and its manual. For developers, see "defining new commands".

Extensions

magit-filenotify: refresh status buffer when git tree changes

This module, to be installed with ELPA, comes with a minor mode magit-filenotify which tracks changes in the source tree using file-notify and refreshes the magit status buffer. Emacs 24.4 with `file-notify-support' is required for it to work.

home and documentation: https://github.com/magit/magit-filenotify

magit-todos

magit-todos displays keyword entries from source code comments and Org files in the Magit status buffer. Activating an item jumps to it in its file. By default, it uses keywords from hl-todo, minus a few (like NOTE).

Magit-todo.png

See Also

Project Pages