Rebasing in Magit

💥 Check out this trending post from Hacker News 📖

📂 **Category**:

💡 **What You’ll Learn**:

Here I have opened the git log1 I’m sorry about the mouse cursor – it’s an
artifact of selecting the area to screenshot.
, by first opening Magit (which I
have bound to the F3 key), and then pressing lL. The first l is the prefix
key for dealing with the git log, and the second L is to to view the log for
all local branches (and the remote branches they track.)

magit-rebase-01.png

Hypothetically, if we wanted to run a more complicated log command, it is very
easy to do that in Magit. When we press the first l and pause for a moment,
Magit shows us unintrusive hints for all options that are available:

magit-rebase-02.png

This means we don’t have to remember exactly which options there are because if
we need them, Magit will remind us. Some examples:

  • To limit to a particular author, we type -A and then Magit gives us a
    fuzzy-matching list of all repository authors. We can either browse that list,
    or type the name of the author we are interested in and press return to
    confirm.
  • To limit the date range of the log, we type =u and then Magit gives us a
    calendar view in which we can select a date, or type one manually.
  • Then we want a graph view with colour and decorations and no merge commits.
    This is already enabled by default in this configuration. (Indicated by bold
    and highlighted flag names.)
  • We want to see file diffstats, so we type -s.
  • Oh, and we only care about files in the tests subdirectory, so we type --
    to limit to files and then type tests and confirm with return.

With this configuration, we want to look at all branches, including remote ones.
We get that view by finally pressing b.

This is a high level of discoverability for git! I have always been that guy
listed in git.txt, but Magit’s discoverability still teaches me a lot of new
ways to use git. But it’s not only discoverable, it’s also quick. Here’s the
full sequence of keypresses, with ␍ standing for confirming with return:

l-Akqr␍=u2025-06-01␍-s--tests␍b

That looks complicated, but remember how we built it: we looked at the hints and
selected one option at a time. Now, if this is a log type we’ll use often, we
are going to start to be able to write out that incantation without even looking
at the hints. It’s both discoverable and efficient.

The corresponding git command in the shell would have been

$ git log --branches --remote --author=kqr --until=2025-06-01 \
   --graph --color --decorate --no-merges --stat -- tests

How do I know? Because it’s right there in the Magit log hints! If Magit
hadn’t told me, I would have to spend a lot of time going back and forth between
the man page and the command line.

People worry that if you use more interactive interfaces to git, you’ll get
worse at managing the git command line. Not so with Magit. Magit is completely
transparent and encourages you to understand which git commands it is executing
under the hood.

This might seem like an excessive rant about the git log in an article
ostensibly about rebasing, but there’s a reason for that: the git log is how
we’ll understand the structure of our repo. And because in Magit, the git log is
interactive.

💬 **What’s your take?**
Share your thoughts in the comments below!

#️⃣ **#Rebasing #Magit**

🕒 **Posted on**: 1773153641

🌟 **Want more?** Click here for more info! 🌟

By

Leave a Reply

Your email address will not be published. Required fields are marked *