Using Magit

Installation

Install the Magit via Melpa.

Magit Interface

../../_images/magit-interface.png

Key

Meaning

C-x g

open Magit interface

C-x k

close current buffer

C-g

abort current operation

Basic Operations

The most important activities in git revolve around staging, committing, and pushing your edits.

New and Unstaged Changes

Magit lists new files under Untracked files. It lists edited files under Unstaged changes.

../../_images/basic-operations-unstaged.png

Key

Meaning

s

stage file

k

kill changes

Staged Changes

After changes are staged, we commit them.

../../_images/basic-operations-staged.png

Key

Meaning

c c

commit staged changes

u

unstage

Commit

../../_images/basic-operations-commit.png

Key

Meaning

C-c C-c

commit with message

Push to Origin

Key

Meaning

P u

push to origin

Pull and Fetch from Origin

Key

Meaning

F u

pull from origin

f u

fetch from origin

Managing Branches

Create a New Branch

Key

Meaning

b c ENT

create a new branch at current branch

P u

push to origin

Squash Commits

Key

Meaning

r i

interactive rebase

c

mark commit to keep

f

mark commit to fixup (will vanish)

P - f u

force-push to origin

Rebase and Resolve Conflicts

Resolving Conflicts

Key

Meaning

f u

fetch changes

r e

rebase up to selected commit

Synchronize with Upstream Repository

Key

Meaning

M a upstream ENT

add remote “upstream”

f u

fetch changes from all sites

r e upstream/master ENT

rebase onto upstream branch

P - f u

force-push to origin