My Emacs Magit workflow.
Posted on November 24th, 2012 in emacs, git | No Comments »
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 diffin 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 file2or 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 ito 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
sto stage those changes oruto unstage those changes. - Optionally, I can look through diffs code and do the same
sanduto 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
cto open the magit-edit-log. I type my commit message and then typeC-c C-cto commit it. ThenPto 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 git push.
And as previously posted, don’t forget to change Magit’s default diff colors!
