Emacs “Magit” is Git Magic

Emacs Magit is Git Magic

The question about Git is “command line” or “GUI”? Most popular text editors and integrated development environments (IDEs) now integrate the basic version control feature set into the application itself. For others, they will complete their work in the text editor and switch over to the terminal emulator to run their favorite Git commands. But what are your options for integrating Git into the Emacs text editor? There are some basic version control features built in, but many users are discovering that the Magit git client for Emacs is a dream version control manager for productivity magic. This article will provide you with everything you need to get up and running with Magit in Emacs.

What is Magit?

In the most basic sense, Magit is a plug-in for Emacs. But more than that, it’s like an entire application unto itself. The focus of Magit is to masterfully integrate all of the Git functionality you would need so you would not require a switch over to command line or graphical Git application.

How to Install Magit

Installing Magit is pretty simple. You can use the default package-install command in Emacs. However, you must make sure that you have the Melpa package manager archives available to you first. If you have not integrated the Melpa package archive already, just add this to your system configuration:

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Comment/uncomment this line to enable MELPA Stable if desired.  See `package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do this.
;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)

To make sure the Melpa package is enabled, you can evaluate the lisp code above, or place it in your init file and restart Emacs. You may also want to run the package-refresh-contents function to make sure your package archives are up to date and available.

When that’s done, you can run the package-install directive as follows:

M-x package-install <RET> magit <RET>

Basic Commands

Now you should have a running Magit client available in your Emacs configuration.

To start going quickly, you can visit a file that is already version control and run the command to open Magit (to follow), or, if the working directory you visited in not under Git version control, Magit will create a Git repository at the visited location. Open Magit with the following:

C-x g

You will be prompted, in another window, with a list of staged and unstaged changes and recent commits. This is main Magit menu.

Getting Help

Before doing anything else, make sure you know how to get help with Magit by pressing h. This will give you a listing of all the commands you can run with Magit. You’ll notice that they match up with just about every Git command you would need.

Stage and Commit

To stage and unstage use the s and u keys with your cursor (or, “point”) over the file you want to stage or unstage. When ready to commit, just click c. Then, when prompted click c again to put in a commit message. All done, click C-c C-c to complete your commit.

As you get more comfortable moving in and out of Magit for all of your Git needs, you will take advantage of more advanced options. But for now, those are the basics of using the Magit Git client for Emacs.

Experience full control over your server environment and deploy the best operating and management systems that fit your needs with our reliable Cloud VPS Hosting!

Christopher Maiorana Content Writer II

Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.

More Articles by Christopher

Was this article helpful? Join the conversation!

Leap into Savings
Leap Ahead with Limited Time Deals