At the bottom of my Emacs 23 editor, I notice that Emacs is aware that I am working in a directory that is under version control, what that version control system is, and what branch I am currently on. Pretty cool! But say I am on the master branch, and from the command line I do a git commit
, followed by a git checkout <branch>
. Emacs still shows me being on the master branch. How do I refresh Emacs so that it reflects the branch I am currently on without closing down all my buffers and restarting it?
Asked
Active
Viewed 2,998 times
13

Houdini
- 3,442
- 9
- 31
- 47
-
What happens if you just reload the file? – gcbenison Jun 11 '13 at 18:09
-
Is there an Emacs command to reload the file? – Houdini Jun 11 '13 at 18:11
-
1`revert-buffer` like giordano suggested – Bleeding Fingers Jun 11 '13 at 18:12
3 Answers
15
M-x revert-buffer
but I suggest you to use magit-mode
to manage your git repos in Emacs.
For the record, I use to bind revert-buffer
to F5:
(global-set-key [f5] 'revert-buffer)

giordano
- 8,087
- 3
- 23
- 48
-
Thanks a lot! Key-binding is perfect for now, but later looks like `magit-mode` is a more permanent solution. – Houdini Jun 11 '13 at 18:27
-
5@Houdini to avoid the annoying confirmation everytime you hit *F5*. Use `(global-set-key [f5] (lambda () (interactive) (revert-buffer nil t)))` – Bleeding Fingers Jun 11 '13 at 19:31
10
You can revert buffer automatically by enable global-auto-revert-mode. If you want to enable it, please add following code to your configuration file.
(global-auto-revert-mode 1)
(setq auto-revert-check-vc-info t)

syohex
- 2,293
- 17
- 16
-
1If you open too many buffers, and your machine is hot, then you should set `auto-revert-interval' much bigger. – ngn999 Jul 19 '16 at 14:04
6
To add to giordano's answer, if many files, which are under git, are opened. Then open ibuffer (M-xibuffer
) mark the buffers you want to reload using m and then E followed by (revert-buffer nil t)
.

Bleeding Fingers
- 6,993
- 7
- 46
- 74
-
1No need for the eval -- `V` runs `ibuffer-do-revert`. And of course there are many ways to mark buffers en-masse in ibuffer, so use `C-h m` to check out its features if you're unfamiliar with it. – phils Jun 11 '13 at 23:17
-
3In addition, if you're mixing ibuffer and version control, you probably want to check out [ibuffer-vc](https://github.com/purcell/ibuffer-vc) as well. – phils Jun 11 '13 at 23:26
-
Great thanks phils. I am finally starting to try using my version control system and editor in conjunction with each other, as opposed to jumping back to the command line for `git` commands. – Houdini Jun 12 '13 at 18:05