1 \input texinfo.tex @c -*-texinfo-*-
3 @setfilename magit.info
4 @settitle Magit User Manual
9 * Magit: (magit). Using Git from Emacs with Magit.
13 Copyright @copyright{} 2008 Marius Vollmer
16 Permission is granted to copy, distribute and/or modify this document
17 under the terms of the GNU Free Documentation License, Version 1.2 or
18 any later version published by the Free Software Foundation; with no
19 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
25 @top Magit User Manual
27 Magit is an interface to the version control system Git, implemented
28 as an extension to Emacs.
35 * Staging and Committing::
46 * Pushing and Pulling::
47 * Interfacing with Subversion::
53 With Magit, you can inspect and modify your Git repositories with
54 Emacs. You can review and commit the changes you have made to the
55 tracked files, for example, and you can browse the history of past
56 changes. There is support for cherry picking, reverting, merging,
57 rebasing, and other common Git operations.
59 Magit is not a complete interface to Git; it just aims to make the
60 most common Git operations convenient. Thus, Magit will likely not
61 save you from learning Git itself.
63 This manual provides a tour of all Magit features. It does not give a
64 introduction to version control in general, or to Git in particular.
66 The main entry point to Magit is @kbd{M-x magit-status}, which will
67 put you in Magit's status buffer. You will be using it frequently, so
68 it is probably a good idea to bind @code{magit-status} to a key of
71 In addition to the status buffer, Magit will also create buffers that
72 show lists of commits, buffers with diffs, and other kinds of buffers.
73 All these buffers are in @code{magit-mode} and have the same key
74 bindings. Not all commands make sense in all contexts, but a given
75 key will always do the same thing in all Magit buffers.
77 Naturally, Magit runs the @code{git} command to do most of the work.
78 The @code{*magit-process*} buffer contains the transcript of the most
79 recent command. You can switch to it with @kbd{$}.
82 @chapter Acknowledgments
84 From day one of the first Magit announcement, John Wiegley, Linh Dang,
85 and Christian Neukirchen have contributed fixes, UI improvements, and
88 Phil Hagelberg joined a few days later. Thanks!
90 Alex Ott contributed support for git svn. Thanks!
92 Marcin Bachry contributed bug fixes and support for decorated logs.
98 Running @kbd{M-x magit-status} displays the main interface of Magit,
99 the status buffer. You can have multiple status buffers active at the
100 same time, each associated with its own Git repository.
102 You need to explicitly refresh the status buffer when you have made
103 changes to the repository from outside of Emacs. You can type @kbd{g}
104 in the status buffer itself, or just use @kbd{M-x magit-status}
105 instead of @kbd{C-x b} when switching to it. You also need to refresh
106 the status buffer in this way after saving a file in Emacs.
108 The header at the top of the status buffer shows a short summary of
109 the repository state: where it is located, which branch is checked
110 out, etc. Below the header are a number of sections that show details
111 about the working tree and the staging area. Only sections that are
114 You control how much of a section is visible by moving point to its
115 title and hitting @kbd{TAB} or @kbd{S-TAB}. Hitting @kbd{TAB} will
116 toggle between hiding and showing the section. A hidden section only
117 shows its first line. You can also control the visibility of
118 sub-sections in this way. Hitting @kbd{S-TAB} will fully expand a
119 section by showing it and all of its sub-sections. If a section is
120 already fully expanded, @kbd{S-TAB} will collapse it: the section
121 itself remains shown, but all its immediate sub-sections are hidden.
123 The first section shows @emph{Untracked files}, if there are any. See
124 @ref{Untracked files} for more details.
126 Two section show your local changes. They are explained fully in the
127 next chapter, @ref{Staging and Committing}.
129 If the current branch is associated with a remote tracking branch, the
130 status buffer shows the differences between the current branch and the
131 tracking branch. See @ref{Pushing and Pulling} for more information.
133 During a history rewriting session, the status buffer shows the
134 @emph{Pending changes} and @emph{Pending commits} sections. See
135 @ref{Rewriting} for more details.
137 Typing a digit in the status buffer will move point to a section
138 header: @kbd{1} will move to @emph{Untracked files}, @kbd{2} will move
139 to @emph{Unstaged changes} or @emph{Changes}, @kbd{3} will move to
140 @emph{Staged changes}, and @kbd{4} will move to @emph{Unpushed
141 commits}. Note that these relations are fixed, @kbd{3} always moves
142 to @emph{Unstaged changes}, not the third visible section.
144 @node Untracked files
145 @chapter Untracked files
147 Untracked files are shown in the @emph{Untracked files} section.
149 You can add a untracked file to the staging area with @kbd{s}.
151 You can instruct Git to ignore them by typing @kbd{i}. This will add
152 the filename to the @code{.gitignore} file. Typing @kbd{C-u i} will
153 ask you for the name of the file to ignore. This is useful to ignore
154 whole directories, for example. The @kbd{I} command is similar to
155 @kbd{i} but will add the file to @code{.git/info/exclude} instead.
157 To delete a untracked file forever, use @kbd{k}.
159 @node Staging and Committing
160 @chapter Staging and Committing
162 Comitting with Git is a two step process: first you add the changes
163 you want to commit to a 'staging area', and then you commit them to
164 the repository. This allows you to only commit a subset of your local
167 Magit allows you to ignore the staging area if you wish. As long as
168 your staging area is unused, Magit will show your uncomitted changes
169 in a section named @emph{Changes}.
171 When the staging area is in use, Magit uses two sections:
172 @emph{Unstaged changes} and @emph{Staged changes}. The @emph{Staged
173 changes} section shows the changes that will be included in the next
174 commit, while the @emph{Unstaged changes} section shows the changes
175 that will be left out.
177 To move a unstaged hunk into the staging area, move point into the
178 hunk and type @kbd{s}. Likewise, to unstage a hunk, move point into
179 it and type @kbd{u}. If point is in a diff header when you type
180 @kbd{s} or @kbd{u}, all hunks belonging to that diff are moved at the
183 If the region is active when you type @kbd{s} or @kbd{u}, only the
184 changes in the region are staged or unstaged. (This works line by
185 line: if the beginning of a line is in the region it is included in
186 the changes, otherwise it is not.)
188 To move all hunks of all diffs into the staging area in one go, type
189 @kbd{S}. To unstage everything, type @kbd{U}.
191 You can discard uncommitted changes by moving point into a hunk and
192 typing @kbd{k}. The changes to discard are selected as with @kbd{s}
195 Before committing, you should write a short description of the
198 Type @kbd{c} to pop up a buffer where you can write your change
199 description. Once you are happy with the description, type @kbd{C-c
200 C-c} in that buffer to perform the commit. When your stagin area is
201 unused at this point, all your uncommitted changes are committed.
202 When the staging area is in use, only the staged changes are
205 You can type @kbd{C-c C-a} in the buffer with the change description
206 toggles a flag that determines whether the next commit will be a
209 Typing @kbd{C} will also pop up the change description buffer, but in
210 addition, it will try to insert a ChangeLog-style entry for the change
216 To show the repository history of your current head, type @kbd{l}. A
217 new buffer will be shown that displays the history in a terse form.
218 The first paragraph of each commit message is displayed, next to a
219 representation of the relationships between commits.
221 Typing @kbd{L} will ask for the starting and end point of the history.
222 This can be used to show the commits that are in one branch, but not
223 in another, for example.
225 You can move point to a commit and then cause various things to happen
226 with it. (The following commands work in any list of commit, such as
227 the one shown in the @emph{Unpushed commits} section.)
229 Typing @kbd{RET} will pop up more information about the current commit
230 and move point into the new buffer. Typing @kbd{SPC} and @kbd{DEL}
231 will also show the information, but will scroll the new buffer up or
232 down when typed again.
234 Typing @kbd{a} will apply the current commit to your current branch.
235 This is useful when you are browsing the history of some other branch
236 and you want to `cherry-pick' some changes from it. A typical
237 situation is applying selected bug fixes from the development version
238 of a program to a release branch. The cherry-picked changes will not
239 be committed automatically; you need to do that explicitly.
241 Typing @kbd{A} will cherry-pick the current commit and will also
242 commit the changes automatically when there have not been any
245 Typing @kbd{v} will revert the current commit. Thus, it will apply
246 the changes made by that commit in reverse. This is obviously useful
247 to cleanly undo changes that turned out to be wrong. As with @kbd{a},
248 you need to commit the changes explicitly.
250 Typing @kbd{C-w} will copy the sha1 of the current commit into the
253 Typing @kbd{=} will show the differences from the current commit to
254 the @dfn{marked} commit.
256 You can mark the current commit by typing @kbd{.}. Some commands,
257 such as @kbd{=}, will use the current commit and the marked commit as
258 implicit arguments. Other commands will offer the marked commit as a
259 default when prompting for their arguments.
264 You can use @kbd{h} and @kbd{H} to browse your @emph{reflog}, the
265 local history of changes made to your repository heads. Typing
266 @kbd{H} will ask for a head, while @kbd{h} will show the reflog of
269 The resulting buffer is just like the buffer produced by @kbd{l} and
270 @kbd{L} that shows the commit history.
275 To show the changes from you working tree to another revision, type
276 @kbd{d}. To show the changes between two arbitrary revisions, type
279 You can use @kbd{a} within the diff output to apply the changes to
280 your working tree. As usual when point is in a diff header for a
281 file, all changes for that file are applied, and when it is in a hunk,
282 only that hunk is. When the region is active, the applied changes are
283 restricted to that region.
285 Typing @kbd{v} will apply the selected changes in reverse.
290 Typing @kbd{t} will make a lighweight tag. Typing @kbd{T} will make a
291 annotated tag. It will put you in the normal @code{*magit-log-edit}
292 buffer for writing commit messages, but typing @kbd{C-c C-c} in it
293 will make the tag instead. This is controlled by the @code{Tag} field
294 that will be added to the @code{*magit-log-edit*} buffer. You can
295 edit it, if you like.
300 Once you have added a commit to your local repository, you can not
301 change that commit anymore in any way. But you can reset your current
302 head to an earlier commit and start over.
304 If you have published your history already, rewriting it in this way
305 can be confusing and should be avoided. However, rewriting your local
306 history is fine and it is often cleaner to fix mistakes this way than
307 by reverting commits (with @kbd{v}, for example).
309 Typing @kbd{x} will ask for a revision and reset your current head to
310 it. No changes will be made to your working tree and staging area.
311 Thus, the @emph{Staged changes} section in the status buffer will show
312 the changes that you have removed from your commit history. You can
313 commit the changes again as if you had just made them, thus rewriting
316 Typing @kbd{x} while point is in a line that describes a commit will
317 offer this commit as the default revision to reset to. Thus, you can
318 move point to one of the commits in the @emph{Unpushed commits}
319 section and hit @kbd{x RET} to reset your current head to it.
321 Type @kbd{X} to reset your working tree and staging area to the most
322 recently committed state. This will discard your local modifications,
328 You can create a new stash with @kbd{z}. Your stashes will be listed
329 in the status buffer, and you can apply them with @kbd{a} and pop them
330 with @kbd{A}. To drop a stash, use @kbd{k}.
335 The current branch is indicated in the header of the status buffer.
336 You can switch to a different branch by typing @kbd{b}. This will
337 immediately checkout the branch into your working copy, so you
338 shouldn't have any local modifications when switching branches.
340 Similar to @kbd{x}, typing @kbd{b} while point is at a commit
341 description will offer that commit as the default to switch to.
342 This will result in a detached head.
344 To create a new branch and switch to it immediately, type @kbd{B}.
349 Magit offers two ways to merge branches: manually and automatic. A
350 manual merge will apply all changes to your working tree and staging
351 area, but will not commit them, while a automatic merge will go ahead
352 and commit them immediately.
354 Type @kbd{m} to initiate a manual merge, and type @kbd{M} for a
357 A manual merge is useful when carefully merging a new feature that you
358 want to review and test before even committing it. A automatic merge
359 is appropriate when you are on a feature branch and want to catch up
360 with the master, say.
362 After initiating a manual merge, the header of the status buffer will
363 remind you that the next commit will be a merge commit (with more than
364 one parent). If you want to abort a manual merge, just do a hard
365 reset to HEAD with @kbd{X}.
367 Merges can fail if the two branches you merge want to introduce
368 conflicting changes. In that case, the automatic merge stops before
369 the commit, essentially falling back to a manual merge. You need to
370 resolve the conflicts and stage the resolved files, for example with
373 You can not stage individual hunks one by one as you resolve them, you
374 can only stage whole files once all conflicts in them have been
380 Typing @kbd{R} in the status buffer will initiate a rebase or, if one
381 is already in progress, ask you how to continue.
383 When a rebase is stopped in the middle because of a conflict, the
384 header of the status buffer will indicate how far along you are in the
385 series of commits that are being replayed.
387 Of course, you can initiate a rebase in any number of ways, by
388 configuring @code{git pull} to rebase instead of merge, for example.
389 Such a rebase can be finished with @kbd{R} as well.
394 As hinted at earlier, you can rewrite your commit history. For
395 example, you can reset he current head to an earlier commit with
396 @kbd{x}. This leaves the working tree unchanged, and the status
397 buffer will show all the changes that have been made since that new
398 value of the current head. You can commit these changes again,
399 possibly splitting them into multiple commits as you go along.
401 Amending your last commit is a common special case of rewriting
404 Another common way to rewrite history is to reset the head to an
405 earlier commit, and then to cherry pick the previous commits in a
406 different order. You could pick them from the reflog, for example.
408 Magit has several commands that can simplify the book keeping
409 associated with rewriting. These commands all start with the @kbd{r}
412 Typing @kbd{r s} will start a rewrite operation. You will be prompted
413 for a @emph{base} commit, and all commits between the current head and
414 this commit are put in a list of @emph{Pending commits} (including the
415 base commit). The current head will then be reset to the parent of
418 You would then typically use @kbd{a} and @kbd{A} to cherry pick
419 commits from the list of pending commits in the desired order, until
420 all have been applied. Magit shows which commits have been applied by
421 changing their marker from @code{*} to @code{.}.
423 Using @kbd{A} will immediately commit the commit (as usual). If you
424 want to combine multiple previous commits into a single new one, use
425 @kbd{a} to apply them all to your working tree, and then commit them
428 Magit has no explicit support for rewriting merge commits. It will
429 happily include merge commits in the list of pending commits, but
430 there is no way of replaying them automatically. You have to redo the
433 You can also use @kbd{v} to revert a commit when you have changed your
434 mind. This will change the @code{.} mark back to @code{*}.
436 Once you are done with the rewrite, type @kbd{r t} to remove the book
437 keeping information from the status buffer.
439 If you rather wish to start over, type @kbd{r a}. This will abort the
440 rewriting, resetting the current head back to the value it had before
441 the rewrite was started with @kbd{r s}.
443 Typing @kbd{r f} will @emph{finish} the rewrite: it will apply all
444 unused commits one after the other, as if you would us @kbd{A} with
447 You can change the @kbd{*} and @kbd{.} marks of a pending commit
448 explicitly with @kbd{r *} and @kbd{r .}.
450 In addition to a list of pending commits, the status buffer will show
451 the @emph{Pending changes}. This section shows the diff between the
452 original head and the current head. You can use it to review the
453 changes that you still need to rewrite, and you can apply hunks from
454 it, like from any other diff.
456 @node Pushing and Pulling
457 @chapter Pushing and Pulling
459 Magit will run @code{git push} when you type @kbd{P}. If you give a
460 prefix argument to @kbd{P}, you will be prompted for the repository to
461 push to. When no default remote repositor has been configured yet for
462 the current branch, you will be prompted as well. Typing @kbd{P} will
463 only push the current branch to the remote. In other words, it will
464 run @code{git push <remote> <branch>}.
466 Typing @kbd{f} will run @code{git remote update} and @kbd{F} will run
467 @code{git pull}. You should have setup your Git configuration to do
468 the right thing for @code{git pull}.
470 If there is a default remote repository for the current branch, Magit
471 will show that repository in the status buffer header.
473 In this case, the status buffer will also have a @emph{Unpushed
474 commits} section that shows the commits on your current head that are
475 not in the branch named @code{<remote>/<branch>}. This section works
476 just like the history buffer: you can see details about a commit with
477 @kbd{RET}, compare two of them with @kbd{.} and @kbd{=}, and you can
478 reset your current head to one of them with @kbd{x}, for example.
480 When the remote branch has changes that are not in the current branch,
481 Magit shows them in a section called @emph{Unpulled changes}. Typing
482 @kbd{F} will merge them into the current branch.
484 @node Interfacing with Subversion
485 @chapter Interfacing with Subversion
487 Typing @kbd{N r} runs @code{git svn rebase} and typing @kbd{N c} runs
488 @code{git svn dcommit}.