Magit-QuickStart
March 9, 2020
Magit is an interface to the version control system Git, implemented as an Emacs package. Magit aspires to be a complete Git porcelain. While we cannot (yet) claim that Magit wraps and improves upon each and every Git command, it is complete enough to allow even experienced Git users to perform almost all of their daily version control tasks directly from within Emacs. While many fine Git clients exist, only Magit and Git itself deserve to be called porcelains. # Contents
- contents {:toc}
Show git status
SPCgsshow Magit status view
Show help
SPCgsshow Magit status view?get help
Show git log
SPCgsshow Magit status viewllshow log view
Show all commits for the current file
SPCgflshow git log for the current file
Diff a range of commits
SPCgsshow Magit status viewllshow log view- use
jandkto position the cursor on a commit Vto select the line- use
jandkto position the cursor on another commit drto show a diff of the range of commits
Checkout a local branch
SPCgsshow Magit status viewbbcheckout a branch- select or enter the branch name and hit ENTER
Checkout a commit
SPCgsshow Magit status viewllshow log view- use
jandkto position the cursor on a commit bbENTER to checkout that commit
Checkout a different revision of a file
SPCgsshow Magit status viewllshow log view- move point to the commit you want to checkout (using
jandk) O(capital letter O)freset a file- hit
ENTERto select the default revision selected above. (it will look something like - master) - select a file
qto close the log view and see the file at the selected revision is staged
Open a different revision of a file
SPCgsshow Magit status viewllshow log view- move point to the commit you want to checkout (using
jandk) SPCgff(magit-find-file) to open a file at a revisionENTERto use the selected commit- select the name of the file to open
Create a local branch from a remote branch
SPCgsshow Magit status viewbccreate a branch- select or enter the remote branch and hit
ENTER - hit
ENTERto use the same name or enter a new name and hitENTER
Pull from upstream
SPCgsshow Magit status viewFupull from upstream
Push to upstream
SPCgsshow Magit status viewPupush to upstream
Stage files and commit
SPCgsshow Magit status view- use
jandkto position the cursor on a file TABto show and hide the diff for the filesto stage a file (uto unstage a file andxto discard changes to a file)ccto commit- write a commit message and save with
SPCfs ,cto finish the commit message
Stage specific hunks
SPCgsshow Magit status viewM-n/M-pto move to the “Unstaged changes” sectionj/kto move to the desired fileTABto expand the hunks in the fileM-n/M-pto move to different hunkss/uto stage or unstange hunksxto discard a hunkccto commit- Enter a commit message and save with
SPCfs ,cto finish the commit
Merge master into the current branch
SPCgsshow Magit status viewmmmerge- select or enter master and hit
ENTER
Rebase the current branch onto master
SPCgsshow Magit status viewrerebase- select or enter master and hit
ENTER
Use interactive rebase to squash commits
SPCgsshow Magit status viewllshow log view- use
jandkto position the cursor on a commit rito start the interactive rebase- use
jandkto position the cursor on a commit to squash sto mark the commit as to be squashed. (usesmultiple times to squash multiple commits),cto make it happen- edit the new squashed commit message and save with
SPCfs ,cto finish
Use interactive rebase to reorder commits
SPCgsshow Magit status viewllshow log view- use
jandkto position the cursor on a commit rito start the interactive rebase- use
jandkto position the cursor on a commit to reorder - use
M-korM-jto move the commit up or down ,cto make it happen
Revert a commit
SPCgsshow Magit status viewllshow log view- use
jandkto position the cursor on the commit you want to revert _O(capital letter O) to revert the commit- edit the commit message and save with
SPCfs ,cto finish
(Soft) reset the last commit
SPCgsshow Magit status viewllshow log view- use
jandkto position the cursor one commit before the last one O(capital letter O)sto soft reset- the selected commit should be e.g. master. Hit
ENTER
Stash changes
SPCgsshow Magit status viewzzstash changes- enter stash message and hit
ENTER
Pop stash
SPCgsshow Magit status viewzppop from stash- select the stash to pop and hit
ENTER
Copy git commit SHA
SPCgsshow Magit status viewllshow log view- use
jandkto position the cursor on a commit yscopy the git commit SHA
Copy text from a Magit buffer
SPCgsshow Magit status view\switch to text mode- copy text using normal vim keystrokes
\switch back to Magit mode
Run a shell command
SPCgsshow Magit status view!srun a shell commandenter a command to run and hit
ENTERList all branches
SPCgsshow Magit status viewyrshow refs
Jump to the next/prev section in the status view
SPCgsshow Magit status viewgjjump to the next sectiongkjump to the previous section