This is a fast introduction to Magit, an Emacs mode for Git. It improves productivity a lot by integrating with the best text editor ever and saving you the hassle of typing
git commands. Magit has a gazillion features so we’re gonna explore just the real basics. The most common commands on an average Git workflow.
Alright, the most common thing you’ll do is run
M-x magit-status, so you better bind it to a key.
(global-set-key (kbd "C-c m") 'magit-status)
When running it, Magit opens a status buffer with some info about your current situation. If there’s no git repository here, it prompts to create one. The buffer shows current branch, HEAD message, staged/unstaged files, local/remote, etc. This buffer is where you’ll do Git actions. To quit it, press
Suppose you’ve altered a file. As soon as you go
M-x magit-status (or type
g into that buffer) the git information is refreshed. Now you can add things, unstage changes and commit. Let’s do just that.
p you can move around the files. Press
s to stage or
u to unstage files. When you’re done, do
c to commit. Do another
c to confirm and there you are at the commit message.
To cancel, press
C-c C-k and to confirm the commit,
C-c C-c. As soon as you do that it takes you back to that buffer screen, showing off the latest information.
With this sprint, we’ve covered the following git commands with simple Emacs shortcuts:
$ git init $ git status $ git add $ git rm --cached $ git commit
Now, here’s some extras (remember, all commands apply inside Magit’s buffer only):
To ignore a file (add to
iwhen hovering it.
Sstages everything and
lgives you a short history of the repository.
ttags a selected commit.
aadds a new remote.