git inside emacs

To use magit inside emacs you shoud ask your favorite sysadmin to install magit package.

This documentation is mostly based on …

An introduction to Magit, an Emacs mode for Git
magit.vc

Driving Git With Emacs - Pure Magic With Magit - Part One
Driving Git With Emacs - Part Two - May the Log Be With You

Magit Cheatsheet

Magit faq

M-x magit

Running M-x magit-status displays the main interface of Magit, the status buffer.

When invoking M-x magit-status from within a Git repository, it will switch to the status buffer of that repository. Otherwise, it will prompt for a directory. With a prefix argument, it will always prompt.

If you specify a directory that is not a Git repository, M-x magit-status will offer to initialize it as one.

You need to explicitly refresh the status buffer when you have made changes to the repository from outside of Emacs. You can type g in the status buffer itself. You also need to refresh the status buffer in this way after saving a file in Emacs.

The header at the top of the status buffer shows a short summary of the repository state: where it is located, which branch is checked out, etc. Below the header are a number of sections that show details about the working tree and the staging area.

The first section shows Untracked files, if there are any.

The next two sections show your local changes.

Untracked files

Untracked files are shown in the Untracked files section.

When inside magit console : M-x magit

You can add an untracked file to the staging area with s. If point is on the Untracked files section title when you hit s, all untracked files are staged.

You can instruct Git to ignore them by typing i. This will add the filename to the .gitignore file.

Staging and Committing

Committing with Git is a two step process: first you add the changes you want to commit to a ’staging area’ or ’index’, and then you commit them to the repository.

To move an unstaged hunk into the staging area, move point into the hunk and type s. Likewise, to unstage a hunk, move point into it and type u.

Before committing, you should write a short description of the changes.

Type c c to pop up a buffer where you can write your change description. Once you are happy with the description, type C-c C-c in that buffer to perform the commit.

Pushing and Pulling

Magit will run git push when you type P P.

Typing f f will run git fetch.

Typing F F will run git pull.