Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jkitchin/magit-tutorial


https://github.com/jkitchin/magit-tutorial

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

#+TITLE: Magit tutorial

[[info:magit#Top][info:magit#Top]]

* Basic magit
** Create a git repo
[[info:magit#Repository%20setup][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.

#+BEGIN_SRC emacs-lisp
(magit-init)
#+END_SRC

help:magit-init

** Clone a repo
[[info:magit#Repository%20setup][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%20buffer][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%20and%20unstaging][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%20a%20commit][info:magit#Initiating a commit]]

[[info:magit#Editing%20commit%20messages][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][info:magit#Diffing]]

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

** See the log
[[info:magit#Logging][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][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][info:magit#Pulling]]
In the magit-status window press "F" then "p".

** Run a command-line git command manually
[[info:magit#Running%20Git%20manually][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%20Index][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][info:magit#Reverting]]

Got to the log, select the commit and type "V" then "V".
** Tag a version
[[info:magit#Tagging][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%20branch%20popup][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][info:magit#Merging]]

In the magit-status window press "m", then "m" and select the branch to merge into the current one.
** TODO Resolving conflicts
[[info:magit#Resolving%20conflicts][info:magit#Resolving conflicts]]

You will probably also want to get familiar with [[info:ediff#Top][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][info:magit#Fetching]]

In the magit-status window press "f".

** Add a remote
[[info:magit#Remotes][info:magit#Remotes]]

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

** Stashing
[[info:magit#Stashing][info:magit#Stashing]]

Press "z" in the magit-status window
** Git blame
* Advanced concepts
** Resetting
[[info:magit#Resetting][info:magit#Resetting]]

** Rebasing
[[info:magit#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%20and%20sending%20patches][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%20picking][info:magit#Cherry picking]]

Press "A"

** Apply patches
[[info:magit#Applying%20patches][info:magit#Applying patches]]

** Notes about commits
[[info:magit#Notes][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 ():" (or "Notes:" for
refs/notes/commits).

** Cherry-picking
[[info:magit#Cherry%20picking][info:magit#Cherry picking]]