Abhishek Amralkar
2 min readFeb 16, 2024
Photo by Cristian Escobar on Unsplash

In Emacs Magit is the user interface to the git. Magit is Magic. I have used Magit for the last 5 years and have yet to look back.

Introduction to Magit

Magit is an Emacs package that brings Git functionality directly into your Emacs environment. With Magit you do not need to exit your Emacs.

I manage my own Emacs dot file in org-mode and use use-package to install the packages in Emacs.

(use-package magit
:ensure t
:bind ("C-x g" . magit))

Make sure to install sqlite3 API in Emacs and libsqlite3 packages with your OS

(use-package sqlite3
:ensure t)
sudo apt-get install libsqlite3-dev -y

Key Features

1. Magit Status

The magit-status command provides an overview of the current Git repository status. It shows you staged and unstaged changes, untracked files, and the commit history. Use s to stage changes, u to unstage, and c c to commit.

2. Committing Changes

Magit simplifies the process of committing changes. After staging changes, press c c to open the commit interface. Here, we can write our commit message and commit the changes.

3. Branching and Merging

We can easily create and switch between branches using the b key. Merging branches is straightforward as well; use M-x magit-merge to initiate a merge.

4. Diffs and Viewing Changes

Inspecting changes is a core feature of Magit. Use d to view the diff for a specific file or region. The magit-diff command provides a side-by-side view of changes.

5. Pushing and Pulling

Magit simplifies pushing and pulling changes. After committing our changes, use P to push to the remote repository and F to fetch changes.

6. Magit Forge

Magit Forge is an extension that enhances Magit’s capabilities for working with repositories hosted on platforms like GitHub. It provides features such as creating pull requests and viewing issues.

(use-package forge
:ensure t
:after magit)

Key Bindings

In Magit buffers, we can press ? to access the help buffer for more detailed information on commands and keybindings.

This cheat sheet covers some of the most commonly used Magit commands. For a more comprehensive reference, explore Magit’s documentation and help buffers.