b0rk, (edited )
@b0rk@jvns.ca avatar

my rules for git rebase

permalink: https://wizardzines.com/comics/rules-for-rebasing/

andary,
@andary@mastodon.social avatar

@b0rk this is very timely as I'm in the middle of a messy rebase. I'll follow the advice to abort and do it properly

b0rk,
@b0rk@jvns.ca avatar

@andary did it help?

poppis,
@poppis@eliitin-some.fi avatar

@b0rk some people seem to have a habit of merging main branch to feature as an alternative to rebase on main. any thoughts about that?

b0rk,
@b0rk@jvns.ca avatar

@poppis seems very reasonable, personally i would probably do a "squash and merge" at the end to keep my git history from getting too chaotic

nbartlett,

@b0rk You do actually have to rebase, quite often, if your project is hosted on a Gerrit repo 😓

b0rk,
@b0rk@jvns.ca avatar

@nbartlett why? (i don't know anything about gerrit)

thomasmorin,

@b0rk there's a trap in bullet 1. of your top left box: to do "git rebase -i" to squash all commits into a single one, you need to give as rebase target commit, the fork commit of your dev branch, not main
I would love to know if there's a concise way to tell git rebase to do that

b0rk,
@b0rk@jvns.ca avatar

@thomasmorin i guess there's git rebase -i $(git merge-base main HEAD) but that's kind of a mouthful

nickautomatic,
@nickautomatic@mastodon.social avatar

@b0rk Oh yes, I think point 3 in particular is a golden rule! Rebasing the same branch multiple times and doing one small thing each time is so much more manageable than trying to do it all in one go.

nickautomatic,
@nickautomatic@mastodon.social avatar

@b0rk Also, on point 5: I recently learnt about ORIG_HEAD, which is a reference to where you were before the last rebase, which makes undoing a rebase much easier ("git reset --hard ORIG_HEAD"), and as a result has made me a lot more relaxed about finishing a rebase that turns out to be tricky.

b0rk,
@b0rk@jvns.ca avatar

@nickautomatic thanks I'd never heard of ORIG_HEAD!

arj,

@b0rk I'm intending to write a blog post about this at some point, but I have a technique for reducing big rebases from impossible to tractable https://social.tchncs.de/@arj/111367969139018305

b0rk,
@b0rk@jvns.ca avatar

@arj that's super interesting thanks

sumek,
@sumek@hachyderm.io avatar

@b0rk If rebase is going badly I sometimes do git reset main instead and craft the commits I need. A lot of the times it’s a single commit anyway!

b0rk,
@b0rk@jvns.ca avatar

@sumek oh me too! i might add that.

b0rk,
@b0rk@jvns.ca avatar

a bunch of folks have mentioned that they use rerere to avoid solving the same merge conflict a million times during a rebase. If you use it, do you find it works well? are there any downsides to using it?

tylermumford,
@tylermumford@mas.to avatar

@b0rk I’ve only used it once, but it worked well. I had to fix a big merge conflict with lots of files, and it gave me comfort to know, “I’ll only have to fix this once.”

Anarcat,

@b0rk rerere is great! i turned it on by default everywhere now and barely notice it exists except that some magic happens sometimes. the only downside is if you happen to badly resolve a merge, that might be annoying, and can be a little sticky to fix (because you lost the merge context and forgot rerere exists)

b0rk,
@b0rk@jvns.ca avatar

deleted_by_author

alatiera,
@alatiera@mastodon.social avatar

deleted_by_author

  • Loading...
  • arne_mertz,
    @arne_mertz@mastodon.social avatar

    @alatiera @b0rk thanks for dropping those hints - I'll look it up immediately :)

    arun,

    @alatiera @b0rk this -- I usually do a git rebase -i and then block edit in vim to replace all the pick with fixup in one fell swoop (because the string after that first word doesn't actually matter)

    b0rk,
    @b0rk@jvns.ca avatar

    @arun @alatiera yeah i mean I do that too but it seems annoying for folks who don't use vim

    simontatham,
    @simontatham@hachyderm.io avatar

    @b0rk my usual approach to this is 'git reset --soft HEAD^^^^^' followed by 'git commit' and type a fresh message from scratch. Normally in that situation I didn't particularly want to keep the five old messages anyway…

    chrysn,
    @chrysn@chaos.social avatar

    @b0rk Better yet, I'm still looking for a way to say "squash that last change in with the place where I introduced it". If that was beyond some point (might default to "any remote branch) or there is no clear place where the bug was introduced, that's fine, but I spend way more time than I'd like around small typos finding out which of the 10 commits on my branch I introduced that in.

    b0rk,
    @b0rk@jvns.ca avatar

    @chrysn someone just mentioned git absorb which seems to do that https://github.com/tummychow/git-absorb

    b0rk, (edited )
    @b0rk@jvns.ca avatar

    deleted_by_author

  • Loading...
  • leftpaddotpy,
    @leftpaddotpy@hachyderm.io avatar

    @b0rk I've only ever had this pick the wrong commits or ones out of range of my change branch. not sure if it's because i do branches weird or something else though.

    b0rk,
    @b0rk@jvns.ca avatar

    @leftpaddotpy that's good to know thanks!

    acdha,
    @acdha@code4lib.social avatar

    deleted_by_author

  • Loading...
  • b0rk,
    @b0rk@jvns.ca avatar

    @acdha do you find rerere works well in practice? are there any downsides?

    acdha,
    @acdha@code4lib.social avatar

    deleted_by_author

  • Loading...
  • b0rk,
    @b0rk@jvns.ca avatar

    @acdha thank you!

    remi,
    @remi@ruby.social avatar

    @b0rk When you "don't rebase other people commits" do you even avoid rebasing main on your working branch?

    b0rk,
    @b0rk@jvns.ca avatar

    @remi I don't understand -- do you mean like the "backwards" part of this image? why would you want to do that?

    remi,
    @remi@ruby.social avatar

    @b0rk Nope, I meant the normal rebase.

    b0rk,
    @b0rk@jvns.ca avatar

    @remi there’s no issue with that, it doesn't change anyone else's commits

    atrus,

    @b0rk Have you played with git-rerere? May help in cases like #1.

    (I'm a huge fan of rebasing, and having lots of tiny commits, AND a huge fan of the work and content you're creating to help people learn this stuff!)

    b0rk,
    @b0rk@jvns.ca avatar

    @atrus do you find rerere works well in practice? are there any downsides? i'm considering including it but i'm always wary of giving advice that I haven't personally tried

    mlevison,
    @mlevison@agilealliance.social avatar

    @b0rk wow you’re much kindlier than I on this one.

    I suggest don’t rebase. The results resemble freebasing cocaine, almost always a disaster.

    andi1984,

    @b0rk This is brilliant, Julia! Can you make a poster out of it? 😅

    b0rk,
    @b0rk@jvns.ca avatar

    @andi1984 maybe! do you mean a PDF?

    riamaria,

    @b0rk would you be able to put up a version with your handle/site/signature/watermark on it? I would love to share this with people I teach git to.

    b0rk,
    @b0rk@jvns.ca avatar

    @riamaria done! i edited the post, here's the link https://wizardzines.com/comics/rules-for-rebasing/

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • GTA5RPClips
  • rosin
  • thenastyranch
  • Youngstown
  • InstantRegret
  • slotface
  • osvaldo12
  • kavyap
  • khanakhh
  • Durango
  • megavids
  • everett
  • cisconetworking
  • normalnudes
  • tester
  • ngwrru68w68
  • cubers
  • modclub
  • tacticalgear
  • provamag3
  • Leos
  • anitta
  • JUstTest
  • lostlight
  • All magazines