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) (package-initialize)
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>
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:
You will be prompted, in another window, with a list of staged and unstaged changes and recent commits. This is main Magit menu.
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
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!