I wrote about Magit, the Emacs mode for Git almost two years ago and still use it near-daily since. I love being able to spend most my day within Emacs and not having to drop down to shell to pull or push files. I explained my Magit workflow to a user on Stackoverflow recently, and think it would be helpful to post it here as well for my dear Emacs readers:
My flow goes like this.
- I start the day at work. I type
git diff in command line just to see if I have any uncommitted changes from the previous day (don’t forget to enabled colors!) The reason I do this in command line as apposed to magit is because I’m not in emacs yet.
- I either open the uncomitted files in emacs
emacs file1 file2 or I open some files I’m about to work on.
- I code until I’ve fixed a bug or finished a new feature.
- In emacs I type
C-c i to open up the Magit status window.
- I scroll down to the Changes section and next to each file press tab to see a diff of each changes. I either press
s to stage those changes or
u to unstage those changes.
- Optionally, I can look through diffs code and do the same
u to stage and unstage sections of the code. Useful if I had some debug code somewhere and want to kill it.
- After I’ve confirmed all my changes look good and are staged I type
c to open the magit-edit-log. I type my commit message and then type
C-c C-c to commit it. Then
P to push it. Done!
Note that this sounds like a lot of steps but it becomes quickly natural and the whole process literally takes 30 seconds for me to diff my entire set of changes, stage them, and commit them with a message. All while staying in Emacs. So much easier than dropping down to command line.
Sometimes an error is returned when I do a push via Magit usually caused by new code in the remote repo that I have to pull before I push. In this case
F to pull changes then
P again to push. Honestly for some reason, instead of pulling through magit, I generally just
Ctrl-z in this situation, drop down to shell,
git pull, and
And as previously posted, don’t forget to change Magit’s default diff colors!
I finally got my copy of Learning Gnu Emacs back from a friend. I thought I had finished it but there’s a few chapter’s in there that I actually haven’t read.
Something new I learned (and I’m always learning something new despite two-years of near daily use) is the -u flag which allows you to run another user’s .emacs file on a shared system.
While this is great for it’s intended purpose (for example on a shared dev box at work or while pair-programming on a coworker’s machine) I find it also rocks when you need to su to root. Instead of momentarily putting up with plain old vanilla emacs you can load up your personal settings. It’s like going to a friends house and bringing your old lazy boy and direct tv with you (not that I own a TV). Awesome sauce.
Update: If you’re compiling the latest 23.3 version of Emacs with the GCC from XCode 4, you’re probably getting errors. Follow these steps. Better yet, if you already had a newer version of command line Emacs and Lion gave you a 2007 version, edit your /etc/path so your /usr/local/bin in on top and all should be good again.
Update 02/20/12: The curl URL was invalid on this now, so I went and updated it.
curl -O http://ftp.gnu.org/gnu/emacs/emacs-24.3.tar.gz // 45.5MB
tar -xvzf emacs-24.3.tar.gz
// see if it works with src/emacs -Q
sudo make install
// replace cur vers of emacs
sudo mv /usr/bin/emacs /usr/bin/emacs.bk
sudo cp /usr/local/bin/emacs /usr/bin/emacs
If you want the X version of emacs – the one with the ugly square UI, don’t use the
-without-x flag. I’d recommend just using Carbon Emacs in that case, though. If you do compile with X you may run into some errors. You either need to install those missing packages are disable inline-image support with
-with-jpeg=no --with-png=no --with-gif=no --with-tiff=no. For those writing Obj-c I heard
--with-ns flag is cool.
Posted on February 22nd, 2011 in emacs | 6 Comments »
Magit is an awesome and relatively easy to use git repository manager for Emacs. I was all about Tig (command line git repo manager) until I discovered this beauty and now happily stay inside of emacs throughout my daily development. It’s default diff colors are bad enough to make you run away from open-source as fast as you can, though. Here’s how to improve it so that it’s the standard red and green like every other diff tool:
;; change magit diff colors
(set-face-foreground 'magit-diff-add "green3")
(set-face-foreground 'magit-diff-del "red3")
(when (not window-system)
(set-face-background 'magit-item-highlight "black"))))
tar -xvzf emacs-23.2.tar.gz
if you get the error: “configure: error: You seem to be running X, but no X development libraries”
sudo yum install libXpm-devel.i386 giflib-devel.i386 libtiff-devel.i386 libjpeg-devel.i386
sudo apt-get install libgtk2.0-dev libtiff4-dev libgif-dev libjpeg62-dev libpng12-dev libxpm-dev