Git contribution layer for Spacemacs
Table of Contents
- Working with Git
This layers adds extensive support for git.
- git repository management the indispensable magit package
- git-flow add-on for magit.
- quick in buffer history browsing with git-timemachine.
- quick in buffer last commit message per line with git-messenger
- colorize buffer line by age of commit with smeargle
- gitignore generator with helm-gitignore
- org integration with magit via orgit
New to Magit? Checkout the official intro.
To use this configuration layer, add it to your
~/.spacemacs. You will need to
git to the existing
dotspacemacs-configuration-layers list in this
Magit status fullscreen
To display the
magit status buffer in fullscreen set the variable
t in your
(defun dotspacemacs/user-init () (setq-default git-magit-status-fullscreen t))
Magit auto-complete feature is enabled. For this feature to work best you
have to setup your Git repository directory in your
function, this is the folder where you keep all your git-controlled projects
(the path should end up with a
/ to respect Emacs conventions):
(setq magit-repository-directories '("~/repos/"))
For more information, see Magit-User-Manual#Status-buffer
Magit SVN plugin
For convenience the magit SVN plugin can be activated directly in the Git
layer by setting the variable
(defun dotspacemacs/user-init () (setq-default git-enable-magit-svn-plugin t))
Global git commit mode
Spacemacs can be used as the
$GIT_EDITOR) for editing git
commits messages. To enable this you have to add the following line to your
Of course if your OS does not ship with git (!) you’ll have to install it on your machine. You can download it from the download page.
Git-flow is a standardized branching pattern for git repositories with the aim of making things more manageable. While there are tools to assist with making this easier, these do nothing you couldn’t do manually.
Support requires installation of the git-flow extensions. Please reference their installation page for assistance.
See the commentary section of the package here.
Working with Git
Git commands (start with
|show submodule prompt|
|open a |
|show file commits history|
|highlight regions by age of commits|
|highlight regions by last updated time|
|open a |
|stage current file|
|magit dispatch popup|
|display the last commit message of the current line|
|launch the git time machine|
|unstage current file|
- Highlight by age of commit or last update time is provided by smeargle.
- Git time machine is provided by git-timemachine.
- Git last commit message per line is provided by git-messenger.
Spacemacs uses magit to manage Git repositories.
To open a
status buffer, type in a buffer of a Git repository:
SPC g s.
The central key binding hub of Magit is available on
SPC g m.
Spacemacs uses evil-magit for key bindings in magit buffers (unless your editing style is set to emacs, in which case you get the default magit bindings), which are the standard magit key bindings with some minimal changes to make them comfortable for evil users.
Here are the often used bindings inside a
|open a |
|checkout a branch|
|create a branch|
|pull tracked branch and rebase|
|goto next magit section|
|next visual line|
|goto previous magit section|
|previous visual line|
|next search occurrence|
|previous search occurrence|
|revert item at point|
|push to tracked branch|
|push to matching branch (e.g., upstream/develop to origin/develop)|
|on a file or hunk in a diff: stage the file or hunk|
|on a hunk: increase hunk size|
|on a hunk: decrease hunk size|
|on a file: expand/collapse diff|
|on a staged file: unstage|
|unstage all staged files|
|select multiple lines|
Magit allows you to stage specific lines by selecting them in a diff and hitting
s to stage. Due to inconsistencies between Vim and Emacs editing styles, if
you enter visual line state with
V, you will stage one more line than
intended. To work around this, you can use
v instead (since Magit only stages
whole lines, in any case).
Commit message editing buffer
In a commit message buffer press
C-c C-c to commit the changes with the entered message. Pressing
will discard the commit message.
Interactive rebase buffer
|move line down|
|move line up|
Quick guide for recurring use cases in Magit
- Amend a commit:
l lto open
c aon the commit you want to amend
C-c C-cto submit the changes
- Squash last commit:
l lto open
r eon the second to last commit, it opens the
jto put point on last commit
sto squash it
C-c C-cto continue to the
commit message buffer
C-c C-cagain when you have finished to edit the commit message
- Force push a squashed commit:
- in the
status bufferyou should see the new commit unpushed and the old commit unpulled
P -f Pfor force a push (beware usually it is not recommended to rewrite the history of a public repository, but if you are sure that you are the only one to work on a repository it is ok - i.e. in your fork).
- in the
- Add upstream remote (the parent repository you have forked):
Mto open the
ato add a remote, type the name (i.e.
upstream) and the URL
- Pull changes from upstream (the parent repository you have forked) and push:
F -r C-u Fand choose
upstreamor the name you gave to it
P Pto push the commit to
magit-gitflow provides git-flow commands in its own magit menu.
|open magit-gitflow menu|
Git time machine
git-timemachine allows to quickly browse the commits of the current buffer.
|start git timemachine and initiate transient-state|
|show current commit|
|show next commit|
|show previous commit|
|show previous commit|
|leave transient-state and git timemachine|
|copy current commit hash|
Git links to web services
These key bindings allow to quickly construct URLs pointing to a given commit or lines in a file hosted on Git web services like GitHub, GitLab, Bitbucket…
|on a commit hash, browse to the current file at this commit|
|on a commit hash, create link to the file at this commit and copy it|
|on a region, browse to file at current lines position|
|on a region, create a link to the file highlighting the selected lines|
- You can use the universal argument
SPC uto select a remote repository.
- When the link is opened, the URL is also copied in the kill ring, you can
override this behavior by setting the variable