Skip to content

JohnF1-2/magit-tutorial

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 

Repository files navigation

Magit tutorial

info:magit#Top

Basic magit

Create a git repo

info:magit#Repository setup You can create a git repo with M-x magit-init. This will create a git-repo in the current directory.

(magit-init)

help:magit-init

Clone a repo

info:magit#Repository setup

M-x magit-clone

This will prompt you for a repo, which is either a url, or a path, and a path to clone it to.

help:magit-clone

Check the status of your repo

info:magit#Status buffer

Run M-x magit-status to see the status of your repo.

Press “g” in the window to refresh it.

press “n” (next) or “p” (previous) to navigate in this window.

help:magit-status

Stage a file

info:magit#Staging and unstaging

In the magit-status window, put your cursor on an unstaged file and press “s”.

If you press TAB on the file, it will expand to show the changes that are unstaged. Deletions show in red, and additions in green. The changes are in “hunks”.

You can unstage a file with “u”

Commit a file

info:magit#Initiating a commit

info:magit#Editing commit messages

In the magit-status window with some files that are staged, press “c”, review the options, and probably press “c” again. Enter a commit message and type “C-c C-c” to commit it, or “C-c C-k” to cancel it.

Diffs

info:magit#Diffing

From the magit-status window, press “d” then “d” to see what has changed.

See the log

info:magit#Logging

In the magit-status window press “l”, review the options, and press “l” again.

If you want to see only the commits that affected a file, in the magit-status window press “l” then “=f”, enter the filename, and then press “l” again.

Push

info:magit#Pushing

In the magit-status window press “P” then “p”.

Note that tags don’t normally get pushed, but there are options (“T” to push a tag, and “t” to push all tags).

Pull

info:magit#Pulling In the magit-status window press “F” then “p”.

Run a command-line git command manually

info:magit#Running Git manually In the magit-status window, type “!” to get the popup and choose what you want to do (e.g. where to run the command, etc… You do not need to type “git” in the command. Note you can also run a shell command from this interface.

Check the output of the git command

Press “$”

Keybindings

info:magit#Keystroke Index

Intermediate concepts

Checkout an older version of a file

Use M-x magit-checkout-file select the branch, or enter a revision, and then choose a file.

help:magit-checkout-file

help:magit-find-file help:magit-find-file-other-window

Search the commit messages for a pattern

In a magit-status window press “l =g” enter a pattern to grep for, and then press “l”.

Revert a commit

info:magit#Reverting

Got to the log, select the commit and type “V” then “V”.

Tag a version

info:magit#Tagging

press “t” in the magit-status window. You can then create a tag, annotate it, delete tags, and prune them.

Checkout an existing branch.

info:magit#The branch popup

In the magit-status window press “b” then “b” and choose the branch.

To checkout a new branch, in the magit-status window press “b” then “c”. Choose the branch to start from then a name for the new branch.

Merge two branches

info:magit#Merging

In the magit-status window press “m”, then “m” and select the branch to merge into the current one.

Resolving conflicts

info:magit#Resolving conflicts

You will probably also want to get familiar with info:ediff#Top.

On a file in a magit-status window, press “e” to enter the 3-window ediff view. The A window is the version at HEAD, the B window is what is in the index, and the C window is the current version.

Fetching

info:magit#Fetching

In the magit-status window press “f”.

Add a remote

info:magit#Remotes

M-x magit-remote-add then enter an alias, and the url.

Stashing

info:magit#Stashing

Press “z” in the magit-status window

Git blame

Advanced concepts

Resetting

info:magit#Resetting

Rebasing

info:magit#Rebasing

Interactve rebasing

Open the log, select the oldest commit you want to rebase on then press “r” and then “i”. Use M-p and M-n to move commits around. Press “s” on any commits you want to squash into the commit above it. C-c C-c will start the commands.

From the magit-status on unpushed commits, you can also press “r” to get the rebase popup.

Reword a commit message

“r w” allows you to reword the commit message.

Create patches

info:magit#Creating and sending patches

In magit-status window, press “W”

“W p” creates patches “W r” makes a pull request. This just creates an email with information in it. It is not a GitHUB request, and it is only useful if there is a public, external copy of the repo.

Cherry-picking

info:magit#Cherry picking

Press “A”

Apply patches

info:magit#Applying patches

Notes about commits

info:magit#Notes

Press “T” to attach a note.

A typical use of notes is to supplement a commit message without changing the commit itself. Notes can be shown by git log along with the original commit message. To distinguish these notes from the message stored in the commit object, the notes are indented like the message, after an unindented line saying “Notes (<refname>):” (or “Notes:” for refs/notes/commits).

Cherry-picking

info:magit#Cherry picking

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published