Emacs Magit Quick Start Guide

Emacs magit quick start guide
With our Cloud VPS plans, you can deploy a lightning-fast, reliable cloud platform with built-in redundancy – ensuring the availability of your environment!

The Emacs Magit package brings the power of Git into your Emacs session. You will no longer need to leave your Emacs frame in order to run Git commands. In this article, you’ll learn the basics of getting Magit installed and a few commands to get you off the ground and in motion.

How To Install Magit

For complete installation instructions you should check out the complete Magit installation documentation.

All Emacs users have their own preferences on how they like to install various packages. For detailed installation instructions on installing Magit check out the link above to the complete Magit documentation. Otherwise I’d recommend using the Melpa package manager:

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

Moving Around

To engage Magit just click C-x g while inside of any active Git project. This means you can engage Magit while working on a specific file or while visiting a directory in Dired.

Once inside the Magit buffer, you will see your “Head:” and “Merge:” references at the top followed by a list of files ready for staging along with any untracked files. This view is similar to what you might see when running git status.

Likewise, you will see your recent commits listed in descending order.

You can use n (next) and p (previous) to move down and up respectively or your arrow keys. Use TAB to fold and unfold these various listings.

Adding and Staging

You can stage files for commit using the s key. Likewise, unstage files with the u key. As you click through files and stage them, they will switch from the “Untracked files” to “Staged changes” section of the Magit buffer.

Commit and Push

When you are ready to commit your changes press the c key. Below, you will see options and commands you can run with the commit. If you wish to skip all of those and just commit you can press c again. You will then be prompted to provide your commit message in a new buffer. Fill in your commit message and then C-c C-c when ready. This will complete the commit process.

If you wish to push your commit to a remote repository this is a great time to do it. Your remote repository configuration will be detected by Magit. Press capital P. Here you will put in which location and branch you wish to push.

Branching and Merging

If you wish to create a new branch you can press the b key from within the Magit buffer. Here you will be presented with a list of branching operations. Select the option that applies to your situation.

Later, when you are ready to merge your changes, press the m key, and you will be presented with merge options.

More About Git and Emacs

From this point you will be able to mix and match Magit options to bring all of your Git operations—from the very simple to the very advanced—into your Emacs session.

In order to get a full list of the Magit commands you can run in your project, just open the Magit status buffer with C-x g and then press h.

In order to access the full Magit documentation right from within Emacs hit the C-h i combo to open the Info pages then click m followed by Magit and you can take a deep dive into the documentation. (You can also use the link above to read the HTML manual online or download the PDF.)

Check out these other resources from the support center:

Christopher Maiorana Content Marketing Writer

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? Let us know!