5.1 Status Buffer

While other Magit buffers contain, e.g., one particular diff or one particular log, the status buffer contains the diffs for staged and unstaged changes, logs for unpushed and unpulled commits, lists of stashes and untracked files, and information related to the current branch.

During certain incomplete operations – for example when a merge resulted in a conflict – additional information is displayed that helps proceeding with or aborting the operation.

The command magit-status displays the status buffer belonging to the current repository in another window. This command is used so often that it should be bound globally. We recommend using C-x g:

(global-set-key (kbd "C-x g") 'magit-status)
C-x g (magit-status)

When invoked from within an existing Git repository, then this command shows the status of that repository in a buffer.

If the current directory isn’t located within a Git repository, then this command prompts for an existing repository or an arbitrary directory, depending on the option magit-repository-directories, and the status for the selected repository is shown instead.

  • If that option specifies any existing repositories, then the user is asked to select one of them.
  • Otherwise the user is asked to select an arbitrary directory using regular file-name completion. If the selected directory is the top-level directory of an existing working tree, then the status buffer for that is shown.
  • Otherwise the user is offered to initialize the selected directory as a new repository. After creating the repository its status buffer is shown.

These fallback behaviors can also be forced using one or more prefix arguments:

  • With two prefix arguments (or more precisely a numeric prefix value of 16 or greater) an arbitrary directory is read, which is then acted on as described above. The same could be accomplished using the command magit-init.
  • With a single prefix argument an existing repository is read from the user, or if no repository can be found based on the value of magit-repository-directories, then the behavior is the same as with two prefix arguments.
User Option: magit-repository-directories

List of directories that are Git repositories or contain Git repositories.

Each element has the form (DIRECTORY . DEPTH). DIRECTORY has to be a directory or a directory file-name, a string. DEPTH, an integer, specifies the maximum depth to look for Git repositories. If it is 0, then only add DIRECTORY itself.

This option controls which repositories are being listed by magit-list-repositories. It also affects magit-status (which see) in potentially surprising ways (see above).

Command: magit-status-quick

This command is an alternative to magit-status that usually avoids refreshing the status buffer.

If the status buffer of the current Git repository exists but isn’t being displayed in the selected frame, then it is displayed without being refreshed.

If the status buffer is being displayed in the selected frame, then this command refreshes it.

Prefix arguments have the same meaning as for magit-status, and additionally cause the buffer to be refresh.

To use this command add this to your init file:

(global-set-key (kbd "C-x g") 'magit-status-quick).

If you do that and then for once want to redisplay the buffer and also immediately refresh it, then type C-x g followed by g.

A possible alternative command is magit-display-repository-buffer. It supports displaying any existing Magit buffer that belongs to the current repository; not just the status buffer.

5.1.1 Status Sections

The contents of status buffers is controlled using the hook magit-status-sections-hook. See Section Hooks to learn about such hooks and how to customize them.

User Option: magit-status-sections-hook

This hook is run to insert sections into a status buffer.

The functions described in this section, and the functions magit-insert-status-headers and magit-insert-untracked-files, which are described in subsequent sections, are members of this hook.

Some additional functions that can be added to this hook, but are by default added to another hooks, are listed in References Buffer.

Function: magit-insert-status-headers

Insert header sections appropriate for magit-status-mode buffers. The sections are inserted by running the functions on the hook magit-status-headers-hook. See Status Header Sections.

Function: magit-insert-merge-log

Insert section for the on-going merge. Display the heads that are being merged. If no merge is in progress, do nothing.

Function: magit-insert-rebase-sequence

Insert section for the on-going rebase sequence. If no such sequence is in progress, do nothing.

Function: magit-insert-am-sequence

Insert section for the on-going patch applying sequence. If no such sequence is in progress, do nothing.

Function: magit-insert-sequencer-sequence

Insert section for the on-going cherry-pick or revert sequence. If no such sequence is in progress, do nothing.

Function: magit-insert-bisect-output

While bisecting, insert section with output from git bisect.

Function: magit-insert-bisect-rest

While bisecting, insert section visualizing the bisect state.

Function: magit-insert-bisect-log

While bisecting, insert section logging bisect progress.

Function: magit-insert-unstaged-changes

Insert section showing unstaged changes.

Function: magit-insert-staged-changes

Insert section showing staged changes.

Function: magit-insert-stashes &optional ref heading

Insert the stashes section showing reflog for "refs/stash". If optional REF is non-nil show reflog for that instead. If optional HEADING is non-nil use that as section heading instead of "Stashes:".

Function: magit-insert-unpulled-from-upstream

Insert section showing commits that haven’t been pulled from the upstream branch yet.

Function: magit-insert-unpulled-from-pushremote

Insert section showing commits that haven’t been pulled from the push-remote branch yet.

Function: magit-insert-unpushed-to-upstream-or-recent

Insert section showing unpushed or other recent commits. If an upstream is configured for the current branch and it is behind of the current branch, then show the commits that have not yet been pushed into the upstream branch. If no upstream is configured or if the upstream is not behind of the current branch, then show the last magit-log-section-commit-count commits.

Function: magit-insert-unpushed-to-upstream

Insert section showing commits that haven’t been pushed to the upstream yet.

Function: magit-insert-unpushed-to-pushremote

Insert section showing commits that haven’t been pushed to the push-remote yet.

5.1.2 Status File List Sections

These functions honor the buffer’s file filter, which can be set using D - -.

Function: magit-insert-untracked-files

This function may insert a list of untracked files. Whether it actually does so, depends on the option described next.

User Option: magit-status-show-untracked-files

This option controls whether the above function inserts a list of untracked files in the status buffer.

  • If nil, do not list any untracked files.
  • If t, list untracked files, but if a directory does not contain any tracked files, then only list that directory, not the contained untracked files.
  • If all, then list each individual untracked files. This is can be very slow and is discouraged.

The corresponding values for the Git variable are "no", "normal" and "all".

To disable listing untracked files in a specific repository only, add the following to .dir-locals.el:

((magit-status-mode
 (magit-status-show-untracked-files . "no")))

Alternatively (and mostly for historic reasons), it is possible to use git config to set the repository-local value:

git config set --local status.showUntrackedFiles no

This does not override the (if any) local value of this Lisp variable, but it does override its global value.

See the last section in the git-status(1) manpage, to speed up the part of the work Git is responsible for. Turning that list into sections is also not free, so Magit only lists magit-status-file-list-limit files.

User Option: magit-status-file-list-limit

This option controls many files are listed at most in each section that lists files in the status buffer. For performance reasons, it is recommended that you do not increase this limit.

While the above function is a member of magit-status-section-hook by default, the following functions have to be explicitly added by the user. Because that negatively affects performance, it is recommended that you don’t do that.

Function: magit-insert-tracked-files

Insert a list of tracked files.

Function: magit-insert-ignored-files

Insert a list of ignored files.

Function: magit-insert-skip-worktree-files

Insert a list of skip-worktree files.

Function: magit-insert-assume-unchanged-files

Insert a list of files that are assumed to be unchanged.

5.1.3 Status Log Sections

Function: magit-insert-unpulled-or-recent-commits

Insert section showing unpulled or recent commits. If an upstream is configured for the current branch and it is ahead of the current branch, then show the missing commits. Otherwise, show the last magit-log-section-commit-count commits.

Function: magit-insert-recent-commits

Insert section showing the last magit-log-section-commit-count commits.

User Option: magit-log-section-commit-count

How many recent commits magit-insert-recent-commits and magit-insert-unpulled-or-recent-commits (provided there are no unpulled commits) show.

Function: magit-insert-unpulled-cherries

Insert section showing unpulled commits. Like magit-insert-unpulled-commits but prefix each commit that has not been applied yet (i.e., a commit with a patch-id not shared with any local commit) with "+", and all others with "-".

Function: magit-insert-unpushed-cherries

Insert section showing unpushed commits. Like magit-insert-unpushed-commits but prefix each commit which has not been applied to upstream yet (i.e., a commit with a patch-id not shared with any upstream commit) with "+" and all others with "-".

5.1.4 Status Header Sections

The contents of status buffers is controlled using the hook magit-status-sections-hook (see Status Sections).

By default magit-insert-status-headers is the first member of that hook variable.

Function: magit-insert-status-headers

Insert headers sections appropriate for magit-status-mode buffers. The sections are inserted by running the functions on the hook magit-status-headers-hook.

User Option: magit-status-headers-hook

Hook run to insert headers sections into the status buffer.

This hook is run by magit-insert-status-headers, which in turn has to be a member of magit-status-sections-hook to be used at all.

By default the following functions are members of the above hook:

Function: magit-insert-error-header

Insert a header line showing the message about the Git error that just occurred.

This function is only aware of the last error that occur when Git was run for side-effects. If, for example, an error occurs while generating a diff, then that error won’t be inserted. Refreshing the status buffer causes this section to disappear again.

Function: magit-insert-diff-filter-header

Insert a header line showing the effective diff filters.

Function: magit-insert-head-branch-header

Insert a header line about the current branch or detached HEAD.

Function: magit-insert-upstream-branch-header

Insert a header line about the branch that is usually pulled into the current branch.

Function: magit-insert-push-branch-header

Insert a header line about the branch that the current branch is usually pushed to.

Function: magit-insert-tags-header

Insert a header line about the current and/or next tag, along with the number of commits between the tag and HEAD.

The following functions can also be added to the above hook:

Function: magit-insert-repo-header

Insert a header line showing the path to the repository top-level.

Function: magit-insert-remote-header

Insert a header line about the remote of the current branch.

If no remote is configured for the current branch, then fall back showing the "origin" remote, or if that does not exist the first remote in alphabetic order.

Function: magit-insert-user-header

Insert a header line about the current user.

5.1.5 Status Module Sections

The contents of status buffers is controlled using the hook magit-status-sections-hook (see Status Sections).

By default magit-insert-modules is not a member of that hook variable.

Function: magit-insert-modules

Insert submodule sections.

Hook magit-module-sections-hook controls which module sections are inserted, and option magit-module-sections-nested controls whether they are wrapped in an additional section.

User Option: magit-module-sections-hook

Hook run by magit-insert-modules.

User Option: magit-module-sections-nested

This option controls whether magit-insert-modules wraps inserted sections in an additional section.

If this is non-nil, then only a single top-level section is inserted. If it is nil, then all sections listed in magit-module-sections-hook become top-level sections.

Function: magit-insert-modules-overview

Insert sections for all submodules. For each section insert the path, the branch, and the output of git describe --tags, or, failing that, the abbreviated HEAD commit hash.

Press RET on such a submodule section to show its own status buffer. Press RET on the "Modules" section to display a list of submodules in a separate buffer. This shows additional information not displayed in the super-repository’s status buffer.

Function: magit-insert-modules-unpulled-from-upstream

Insert sections for modules that haven’t been pulled from the upstream yet. These sections can be expanded to show the respective commits.

Function: magit-insert-modules-unpulled-from-pushremote

Insert sections for modules that haven’t been pulled from the push-remote yet. These sections can be expanded to show the respective commits.

Function: magit-insert-modules-unpushed-to-upstream

Insert sections for modules that haven’t been pushed to the upstream yet. These sections can be expanded to show the respective commits.

Function: magit-insert-modules-unpushed-to-pushremote

Insert sections for modules that haven’t been pushed to the push-remote yet. These sections can be expanded to show the respective commits.

5.1.6 Status Options

User Option: magit-status-margin

This option specifies whether the margin is initially shown in Magit-Status mode buffers and how it is formatted.

The value has the form (INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH).

  • If INIT is non-nil, then the margin is shown initially.
  • STYLE controls how to format the author or committer date. It can be one of age (to show the age of the commit), age-abbreviated (to abbreviate the time unit to a character), or a string (suitable for format-time-string) to show the actual date. Option magit-log-margin-show-committer-date controls which date is being displayed.
  • WIDTH controls the width of the margin. This exists for forward compatibility and currently the value should not be changed.
  • AUTHOR controls whether the name of the author is also shown by default.
  • AUTHOR-WIDTH has to be an integer. When the name of the author is shown, then this specifies how much space is used to do so.

Also see the proceeding section for more options concerning status buffers.