Version Control Using Magit in Spacemacs

Table of Contents

There is an official layer called gitbuiltin spacemacs. The git layer is based on magit . Actually, on the magit website, you can always find what you want. This post is a summary of How I use magit in spacemacs.

I like the magit website because of the beautiful font and pleasing color combination. More important is the maintainor Jonas Bernoulli who devotes his yearly efforts to coin the magit great for Emacsers. Now, after a successful campaign on the Kickstarter, Jonas Bernoulli was able to work on Magit full-time for another year, which was he’d love to.

Lets’s goto my daily use of Magit in Spacemacs. If you are not using Spacemacs, I highly recommend it for you.

1 Commit Your Changes

Suppose you have already make some changes on a project version controlled using Git, the next step is to stage the changes and then commit the changes.

If your cursor are in the buffer of a file belonging to that project, press SPC g s will bring you to the magit buffer of current project.

If your cursor are not in the buffer of a file belongint to that project, using SPC p p goto the helm-projectile buffer, then move cursor to the project, then press M-g, you will goto the magit buffer of current project.

Taking my .spacemacs.d project for example, after some modifications on the config, I want to commit the changes. The mentioned two ways bring me to a magit buffer like this:

Figure 1: magit buffer of my .spacemacs.d

Figure 1: magit buffer of my .spacemacs.d

From the above buffer, it records that I have one untracted file and two unstaged changes on two existing files. On the headlines of the untracted files and unstaged changes, press s will stage all the untracted files and unstaged changes. If you are not at the headlines, to stage all the changes you need to press S. After this, the buffer become:

20180219magitbuffer2.png If you regret, press u to unstage the changes. If you want to commit, just press c, you will get a menu.

Figure 3: press `c`  to commit

Figure 3: press `c` to commit

The menu is clear for you to choose. If nothing to change, just press c again, and there will a buffer pop up for you to take some notes on this commit. Also, there is a buffer showing the diff of this commit. If you regret at this moment, just press C-c C-k to abort the commit.

Figure 4: press `c` to commit

Figure 4: press `c` to commit

After finishing the notes, press C-c C-c to finish the commit. you are in a buffer showing the current state of the project.

Figure 5: after commit

Figure 5: after commit

It shows that I am ahead one commit of the remote/master. So, If you want to push the commit to the remote/master, press p , a buffer will popup for you to choose where to push.

Figure 6: press `u`  to push

Figure 6: press `u` to push

Press u to push the commit to the origin/master, and you get:

Figure 7: after pushing to the origin/master

Figure 7: after pushing to the origin/master

Then a commit is finished locally and remotely.

Related

comments powered by Disqus