News for hackers. Stuff that matters.
Re:I Kind of Like Rebasing by AceJohnny2 on Friday June 21, 2024 @06:06PM (#40754344)
I'll add what should be obvious to any seasoned git user: rebase is only possible for "private" commits. If the commits were published, then merge is the only solution, because otherwise with a rebase you will "change (git) history" and break people's repos that have yours as upstream.

I recommend reading this 2008 exchange between top Linux developers learning to use git, and Torvalds's... characteristic language when talking about rebasing a "public" repo:

https://www.yarchive.net/comp/linux/git_rebase.html

(I'm putting "private" and "public" in quotes because they're really on a spectrum)

Re:I Kind of Like Rebasing by ruraljuror on Friday June 21, 2024 @08:06PM (#40755101)
I like your point. The exception is if the project you work on is itself downstream, in which case maintainers will rebase those “published” commits, probably employing the same technique they use to keep their local development branches up-to-date with the downstream project.
Re:I Kind of Like Rebasing by MrDarcy on Saturday June 22, 2024 @06:10PM (#40762643)
In practice it’s fine to rebase and force push to your own published branch, even when it’s an open PR.

Just mark it draft or otherwise communicate when it’s no longer a moving target.

Re:I Kind of Like Rebasing by singpolyma3 on Saturday June 22, 2024 @06:26PM (#40762774)
Especially when it's an open PR. That's effectively essential in order to, say, address feedback
Re:I Kind of Like Rebasing by spankalee on Saturday June 22, 2024 @08:52PM (#40763672)
I try not to rebase and force push for branches under active review though. It makes it much harder for the reviewer to see the changes that have happened since they last reviewed.
Re:I Kind of Like Rebasing by argulane on Sunday June 23, 2024 @06:24AM (#40766294)
That's only a problem when using GitHub. GitLab and Gerrit correctly version such force push PR updates and provide a nice view of what has changed.
Re:I Kind of Like Rebasing by everybodyknows on Sunday June 23, 2024 @10:02AM (#40767530)
I version-number PR branches for upstreams on GitHub. If my branch 'for-upstream-13.0' does not apply cleanly on top of upstream 'main', I sync my fork's 'main' to upstream in GitHub's Web GUI, fetch to my desktop, and build a new 'for-upstream-13.1' on top, with the help of git-cherry-pick. Might need a new PR. All history is preserved, both on GH and locally.
Re:I Kind of Like Rebasing by PaulDavisThe1st on Saturday June 22, 2024 @08:09PM (#40763432)
If you work on a branch also worked on by others, then yes, rebase is "only" possible on private commits.

But if you work on a feature branch, you can publish that branch as long as everybody else understands that it is yours and nobody should push to it. Then you can safely git push --force to the feature branch so that others can (a) see what you're up to (b) test the results. When you're done, you can do a final (or only) rebase against the target branch then merge to that branch.

Re:I Kind of Like Rebasing by smcameron on Saturday June 22, 2024 @09:42PM (#40763937)
> Then you can safely git push --force

What I hate about this workflow is it teaches you to git push --force.

Then one day, you're in the wrong window and you accidentally git push --force on master.

Much prefer a workflow where you never git push --force

Re:I Kind of Like Rebasing by necessary on Saturday June 22, 2024 @10:25PM (#40764210)
Git hosting platforms generally have controls that allow you to prohibit force pushes on protected branches (i.e. master)
Re:I Kind of Like Rebasing by The_Colonel on Sunday June 23, 2024 @01:14AM (#40764985)
This doesn't fix the problem since you still can do a lot of damage doing that on a (perhaps wrong) feature branch.
Re:I Kind of Like Rebasing by SOLAR_FIELDS on Sunday June 23, 2024 @02:19AM (#40765165)
It certainly diminishes it significantly. Very few people are usually collaborating on the same branch together that isn’t the main branch in most orgs. So the chances of you destroying yours or someone else’s work that way is pretty low. You can also branch protect any arbitrary branch, at least on GitHub, though I’ve never been in an org that protects branches other than the main one, besides an org that used release branches. I’ve also never seen someone clobber someone else’s feature branch, though it probably does happen. Much more often people are accidentally clobbering their own branches.

The ability to rewrite history on feature branches is powerful in a good way and slots right into the way Git is philosophically designed. I would probably not be interested in removing that feature to prevent the rare case that someone footguns themselves or someone else

Re:I Kind of Like Rebasing by nickkell on Sunday June 23, 2024 @03:49AM (#40765506)
That's where reflog comes in handy
Re:I Kind of Like Rebasing by zimbu668 on Saturday June 22, 2024 @11:00PM (#40764402)
You should do this instead:

git push —-force-with-lease repo branch

Re:I Kind of Like Rebasing by ajb on Sunday June 23, 2024 @01:13AM (#40764980)
This. --force-with-lease is what --force should have been in the first place. Hopefully they will eventually make it so, and rename --force to something less accessible.
Re:I Kind of Like Rebasing by cortesoft on Sunday June 23, 2024 @12:50AM (#40764893)
Any repo worth its salt shouldn't allow a force push to the main branch.
Re:I Kind of Like Rebasing by ck45 on Sunday June 23, 2024 @04:06AM (#40765577)
I fully agree, and also think that if it's a professional environment pushing to the main branch itself is very questionable for most / code repos. Not only because of the Sarbanes-Oxley Act for public companies.
Re:I Kind of Like Rebasing by patrickthebold on Saturday June 22, 2024 @10:40PM (#40764301)
What annoys me about this is that every branch ends up being "private" and people don't collaborate (In practice). So you end up with: "I can't start work on X until feature Y is merged, and there's a lot of PR comments left unaddressed so let's just merge Y since X is urgent and fix the PR comments later..."
Re:I Kind of Like Rebasing by PaulDavisThe1st on Saturday June 22, 2024 @10:55PM (#40764384)
That's not at all our experience at ardour.org.

Most PRs happen against the main branch, maybe after a private feature branch, maybe not.

Meanwhile, major developments happen in a feature branch, and these are almost always owned by a single person who is responsible for rebasing against the main branch (and eventually merging back there).

But maybe our development team and pace are not good tests for this model.

Re:I Kind of Like Rebasing by kfrzcode on Sunday June 23, 2024 @12:21AM (#40764760)
OT but I love Audour so much. Thanks for you and your team!
Re:I Kind of Like Rebasing by The_Colonel on Sunday June 23, 2024 @01:13AM (#40764976)
> and these are almost always owned by a single person who is responsible for rebasing against the main branch

That still seems very annoying. People have unplanned time-off all the time, live in different timezones, or perhaps are l just busy ATM and can't do the rebase.

Re:I Kind of Like Rebasing by SOLAR_FIELDS on Sunday June 23, 2024 @02:12AM (#40765147)
In practice I’ve found:

- Unplanned time off means the feature just doesn’t make it in

- Living in different time zones means that you just wait and work slows down

In either event, there is rebase and squash auto merge from major git providers like GitHub which helps with this a ton. With that enabled unless the repo is super high traffic usually this is an afterthought unless there is merge conflicts which is semi rare.

That being said, that’s just the reality of what I’ve seen play out in various organizations. I personally like to work off other people branches a lot more than my peers because I work in platform engineering and very often developers come to me with feature branches that need some CI/infra/other change or optimization and very often it’s easiest for me to just drop a commit into their existing branch. The change falls under their ownership and it gets mainlined along with their feature.

Re:I Kind of Like Rebasing by randerson on Sunday June 23, 2024 @08:05AM (#40766814)
This can be mostly avoided with short-lived branches that are merged by the end of each day. If that isn't feasible, people can still collaborate on a feature branch as long as a single person is nominated to rebase it at the end.
Re:I Kind of Like Rebasing by PaulDavisThe1st on Sunday June 23, 2024 @09:41AM (#40767405)
They are the only ones working on the feature branch. If they take a vacation or fall ill or whatever, it causes no issues for anyone else.
Re:I Kind of Like Rebasing by ykonstant on Sunday June 23, 2024 @03:48AM (#40765502)
Off topic, but thank you for having a perfectly modern and beautiful skeuomorphic GUI in Ardour. Tactile buttons with descriptive names instead of vague flat squares with incomprehensible icons; I wish more software offered this kind of interface.
Re:I Kind of Like Rebasing by Shog9 on Saturday June 22, 2024 @11:25PM (#40764513)
My team ran into this early on when attempting to adopt a rebase-preferred workflow for feature branches...

...then we got used to it. A few workflow changes were necessary:

- configure pull.rebase=true. This is kinda just nice in general, but critical if someone might have rebased the branch you're working on overnight. - get used to pushing up your changes regularly - at very least before you quit for the day. - get used to pulling remote changes regularly - at very least before you start work on a branch each day. Rebase after pulling - especially important if you've branched off another feature branch (which may have been rebased). This way you avoid doing a bunch of work on an out of date base. - *Talk to each other.* If it isn't already obvious what a collaborator is doing... Ask them! And err on the side of over communicating what you're doing.

It turns out, all of these behaviors are kinda just generally useful, and after a bit you forget about rebase being the motivation and just enjoy having a bit less friction when working together.

Re:I Kind of Like Rebasing by kalaksi on Sunday June 23, 2024 @04:24AM (#40765677)
If feature Y is incomplete, then sharing a feature branch (which sounds like a road to a messy commit history) doesn't change that. You could also use the unmerged feature branch Y temporarily as a base for X if you need some code from it.
Re:I Kind of Like Rebasing by mikepurvis on Monday June 24, 2024 @04:06PM (#40780090)
People I know used to temp-merge multiple work in progress features into a so-called frankenbranch for testing purposes. It was broadly acknowledged to be a huge smell and reached for only as a last resort.
Re:I Kind of Like Rebasing by watwut on Sunday June 23, 2024 @04:54AM (#40765814)
cooperating on half baked code sux so much, that I happily take the trade off
Re:I Kind of Like Rebasing by another-dave on Sunday June 23, 2024 @07:17AM (#40766561)
Do you think that works any better if you're using merges Vs rebasing though?

If the problem is that you urgently need some small fix in an otherwise broken branch, you can always just cherry-pick that across to your own fresh pr.

Re:I Kind of Like Rebasing by Aeolun on Sunday June 23, 2024 @02:50AM (#40765268)
Never use git push —force. Alway use git push —force-with-lease.

Then if someone changed your remote branch, git will always let you know :)

Re:I Kind of Like Rebasing by arrowsmith on Sunday June 23, 2024 @06:32AM (#40766328)
Been using git every day for ten+ years and I never knew about --force-with-lease.

That's great to have learned, thanks!

Re:I Kind of Like Rebasing by e12e on Sunday June 23, 2024 @08:27AM (#40766945)
I think feature branches typically should be "mostly" private - but sometimes a few quick fixer are better to push, rather than just describe as a review comment.
Re:I Kind of Like Rebasing by forrestthewoods on Sunday June 23, 2024 @06:30AM (#40766319)
> rebase is only possible for "private" commits.

This is false. Well, it can be false. Git sucks and makes it harder then it needs to be.

It’s relatively easy to have multiple people working on a feature branch that is continuously rebased.

Meta’s Mercurial-like VCS system automagically stores 100% of commits in the cloud. Feature branches are anonymous rather than named. It’s all just a tree of commit hashes.

Having multiple people work on one “branch” requires some basic communication as to what is considered “tip”. But since it’s all anonymous there’s no issues with different people incrementing a named branch to different commits.

Honestly it’s pretty simple and easy. Git makes it harder than it actually is.

Re:I Kind of Like Rebasing by rmgk on Sunday June 23, 2024 @10:08AM (#40767583)
As far as I can tell, what is really meant by “rebase is only possible for "private" commits.” is that for public commits, rebasing would require to coordinate with everyone interested in that branch.

This seems to be very similar to what you say with “requires some basic communication as to what is considered ‘tip’”

Requiring coordination (or a constrained model of allowed changes) when modifying things (such as what the tip/branch points to) is a general principle unrelated to git and applies to every workflow.

That said, I do understand that Meta’s centralized tool is more useful for your usecase.

Re:I Kind of Like Rebasing by forrestthewoods on Sunday June 23, 2024 @12:01PM (#40768382)
> I do understand that Meta’s centralized tool is more useful for your usecase.

One of my chief Git complaints is that 99.9% of projects are de facto centralized on GitHub. Genuinely decentralized projects are vanishingly rare.

The way Git auto-advances branch tags causes a lot of pain. Having lots of people commit to a shared feature branch that has lots of rebasing is quite easy when the “tip” is infrequently updated. Each person thinking they can declare the new tip with every commit is the source of pain.

Re:I Kind of Like Rebasing by rmgk on Monday June 24, 2024 @10:41AM (#40776633)
Again, I see where you are coming from, and I do agree that a lot of discussion about Git (and it’s workflow) is really about GitHub (and it’s workflow).

But even when using GitHub as the hosting service, every time you work on a local branch (this includes main/master) you are working on something purely local that will not conflict with what anyone else is doing. It’s only by pushing/pulling that tracking branches are automatically updated, which seems to correspond to the operation that you would refer to as updating tip.

As the rest of the discussion is this topic seems to indication, people do work on these “private” branches a lot, and do rebase/modify them freely to create a history as they like before publishing that history (at which point, you would require coordination with everyone who saw that to change it again).

As far as I can tell, what the Meta tooling seems to offer is that you can see the “kinda private” commits of other people, if I understand correctly. That does sound indeed useful, but also out of scope for Git – rather part of some further UI that displays such information conveniently.

Re:I Kind of Like Rebasing by forgingahead on Monday June 24, 2024 @05:14AM (#40773904)
Thanks for sharing the link. I'm pulling out the valuable summary at the end. I'm not sure what you're alluding to with his language, but it's a clear and articulate post that junior devs, or folks used to working solo, should see to understand the thought process behind it.

===

In other words, you really shouldn't rebase stuff that has been exposed anywhere outside of your own private tree. But within your own private tree, and within the commits that have never seen the light of day, rebasing is fine.

(And yes, there are exceptions. If it's a clear "throw-away tree" all the rules go out the window, of course, as long as everybody involved knows it's a throw-away tree, and know that if they pull it they have to synchronise 100% with you - so within a very tight-knit case or within a very specific small detail that is actively being worked on, those rebases with cleanups make tons of sense).

===