Тёмный

You only Git Merge?!? feat Theo : DevHour #1 

ThePrimeagen
Подписаться 414 тыс.
Просмотров 145 тыс.
50% 1

Theo is a former twitch (5 years) and now currently runs ping.gg where he codes amazing software for streamers. We debate the pros and cons of git rebase vs git merge
Finding Theo
/ t3dotgg
/ theo
/ theobrowne1017
Links
Linode: linode.com/prime
Discord: / discord
Twitch: / theprimeagen
Insta: / theprimeagen
Twitter: / theprimeagen
VimRC & i3: github.com/The...
Keyboard (15% off, I don't earn commission): bit.ly/primeag...
#coding #programming #softwareengineering

Опубликовано:

 

1 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 439   
@neonraytracer8846
@neonraytracer8846 2 года назад
Git is for mortals, just remember everything you did, and have the code memorized in order to paste it back in!
@ThePrimeagen
@ThePrimeagen 2 года назад
the final form
@dorbie
@dorbie 2 года назад
I have literally taken manual copies of my working files before entering more adventurous git commands. That's how much I trust it, and myself.
@neonraytracer8846
@neonraytracer8846 2 года назад
@@dorbie I've not been that diligent, and wiped progress several times! If you're unsure, that's the way to go. My worst one was two weeks of local commits gone, after trying to put it on Github with a different name. Completely erased the git folder trying to sync up the empty remote with my local.
@dorbie
@dorbie 2 года назад
@@neonraytracer8846 You're not an expert git user unless you've blown away work from your working files or local repo. This is why we have a love hate relationship with git, even the masochists who pretend it's all love.
@AmirHosseinHonardust
@AmirHosseinHonardust Год назад
The C++er's mindset.
@jimboxx7
@jimboxx7 2 года назад
Rebase private commits, merge public commits. Never change public history, do whatever you want with private history. By public, I mean 2+ developers depend on it.
@ThePrimeagen
@ThePrimeagen 2 года назад
yeah, this is fairly based take
@lordvalen8133
@lordvalen8133 2 года назад
@@ThePrimeagen Rebased*
@Lexikon00
@Lexikon00 2 года назад
This.
@fadious_padious2711
@fadious_padious2711 2 года назад
Yeah, I rebase the private commits on my working branch. I will often commit on my working branch every so often for safety. However, when I do the merge request I don't want there to be a dozen different commits in the history.
@panthonyy
@panthonyy 2 года назад
@@fadious_padious2711 I do the same. This way, there are no commit messages like "F**K" or "Jeezus Christ" that end up in public history.
@ThePrimeagen
@ThePrimeagen 2 года назад
Devhour deez podcast Hey, give this a like if you like podcast style
@nerminkarapandzic5176
@nerminkarapandzic5176 2 года назад
I like it but what about the devhour meme, it's true now
@henriquegasques
@henriquegasques 2 года назад
Where will the full version be available? (if there is one)
@henriquegasques
@henriquegasques 2 года назад
Just saw your reply to another comment saying it's on twitch :)
@andrewhaeffner6114
@andrewhaeffner6114 2 года назад
“We rebased you out of the chat.” what a way to end a video. pure gold. Appreciate this video, Prime. Things like this always add to my limited perspective
@ThePrimeagen
@ThePrimeagen 2 года назад
hope you enjoy :)
@earthling_parth
@earthling_parth 2 года назад
I laughed out aloud in that 😂
@DebugChug.
@DebugChug. 2 года назад
How often will you be doing these?? This was great!
@ThePrimeagen
@ThePrimeagen 2 года назад
maybe ~once a month. Maybe once every other month.
@Lucas-hh4oh
@Lucas-hh4oh 2 года назад
@@ThePrimeagen nah man, i need you to do it every other week
@lpanebr
@lpanebr 2 года назад
I also loved it. It would only be better if you actually got in a fist fight! I don't even care if you wear boxing gloves.
@aesap_
@aesap_ 2 года назад
I’ll be on the next episode if u want. I’m a shitty developer need help
@typhoon2099
@typhoon2099 2 года назад
I've just started using fixups and my commit history looks so much better. I've also been a fan of rebasing on master/main before opening a PR so that I'm up to date with the repo. Squash merges and fast forwards are great too, one commit per feature makes things pretty readable Imo.
@ThePrimeagen
@ThePrimeagen 2 года назад
Yayayayayayaya exactly how I feel
@Imaltont
@Imaltont 2 года назад
Rebasing and Merging is two different tools for different situations though. Refusing either seems wrong. Rebasing keeps things clean before you merge something into the base. You get a clean history that is nice to work with and reason about. Rebase for your local/private branches to keep up to date with exactly what things look like upstream and to clean up messy commits. Merge to combine branches. Torvald's/Linux' policy is not to rebase anything public, and not to rebase anything from your base, only your own unmerged changes. Rebasing and changing recent history/history of your own changes seems to be common in Linux based on the contribution guidelines to clean up commits and commit messages. Personally I use the history a lot when looking for recent errors or obscure errors in large code bases where it's hard to know where to start bisecting, searching for specific files/patterns, authors, keywords etc. Even just to understand how some things evolved in the files I'm currently working in, to see why or how it ended up in it's current state and not repeat previous errors by just doing the simplest fix possible that was maybe patched out at an earlier point for good reasons. Also use rebasing to clean up my work before merging so there are no broken commits, and if several issues are combined into one branch I'll reorder the changes so they fit in one commit each with the issue number. When I look around at the tools some people use with git I can understand why they never bother with any of the things it can do though, and that is why I pray to the tpope shrine every morning before work.
@ThePrimeagen
@ThePrimeagen 2 года назад
yeah. its also different if you don't work on the web. A versioned product makes merging a requirement as up-version merging has to be done. its not always an option.
@leviackerman7222
@leviackerman7222 2 года назад
This is actually a very informative podcast and this style is epicc
@ThePrimeagen
@ThePrimeagen 2 года назад
ty ty :)
@akashdeepnandi
@akashdeepnandi 2 года назад
I used only git merge until one day I just checked my git tree, it made me cry. From that point on in my life, I knew tough choices have to be made. So git rebase it is.
@Bennevisie
@Bennevisie 2 года назад
Squash commit your private branches and merge them into your public branches. NEVER rebase public branches.
@justinhj1
@justinhj1 2 года назад
I like squash merge from feature branch; the main branch has clean history and the feature branch doesn’t have a modified history.
@ThePrimeagen
@ThePrimeagen 2 года назад
reasonable
@ivar9125
@ivar9125 2 года назад
Main branch has a clean history even without squash. Show First-parent only or whatever it is called..
@justinhj1
@justinhj1 2 года назад
@@ivar9125 TIL
@michaelslattery3050
@michaelslattery3050 2 года назад
I used to. The problem with that is it makes it harder to tell what all was done. I prefer one commit per task (e.g. added a field to a form). I squash multiple commits, if they were part of a single task. Usually git commit --amend --no-edit is all I need for squashing. IMO, the feature branch commits should read like a manifest of things that were done, as much as practical.
@Pictor13
@Pictor13 Год назад
I was a big fan of `rebase` like Primeagen, hated `merge` commits confusing the visual clarity. I also liked to rebase & squash in a single commit. I was kind of OCD on it. With time I started to prefer keeping all those "progression" commits, because they say more "show me how you got there" rather than "show me what you got" (cit). Especially useful re-reading history months/years after, when I forgot 90% of my work. Also, I sometimes tend to ride the flow of the moment, get many parallel ideas and change lot of things, ending up with long-lived branches. On local I ALWAYS rebase, if I am the only contributor of the repo; otherwise I use it as last step to get everything clean and sequencial. However, merge started to be useful a lot when: - working with several colleagues over the same repo; having a separate branch for each small ticket is a godsend, makes the whole interaction on the repo a lot clearer. It makes easier to understand who did what and when and related to what issue, without the noise of having unrelated commits in the way. - using workflow with such colleagues, like `source ticket123-branch from dev-branch` -> `implement & commit` -> `QA ticket123-branch` -> 'merge back into dev-branch` - working on PRs. Yes... unfortunately they don't keep track of old commits that were rebased, ending with code-review comments that refer now commit-SHAs that do not exist anymore. - needing to juggle between deployments that run different versions of the code but that will need to be re-aligned later on. The version on Production can keep adding critical bugfixes, while on Test I can keep evolving in a major/patch version, and merge the critical fixes later on. MY MAIN CONCEPT IS: -- When I work on PRIVATE branches (I prefix them like `pictor/wip/ticket123`), I do ANYTHING with them (apart for merge): wip commits, dirty commits, backup commits, `rebase`, `rebase -i HEAD^^^`, `push --force`, harass commits, beat down branches, slap remotes in da face. And when I'm done, clean everything and swap from "private" to "shared" (what I call a "real commit"): by rebasing in a new `ticket123` branch and pushing it (also caring to delete the now obsolete `pictor/wip/ticket123` ref from remote). -- Once my work become a SHARED branch, if I merge-fast-forward (same result as rebase) I would see only a single sequence of commits and there more thinking load when (in the future) trying to understand the chronology of what happened. While if I merge in a new commit, I can visually see what was merged, related to what, when it started, when it finished, and (in the merge commit) what files were having conflicts). The value of this is great when analysing a repo with lot of parallel work from many contributors. But, yes, IT IS harder to look at, although it is easier to follow. Dunno if all this mess makes sense to anybody else 😁😁😁
@funcmethod
@funcmethod 2 года назад
6:12 "You can't come back from a bad rebase because you've changed history." I think this is the key takeaway. I've often thought this about rebasing-I think I'm persuaded to switch to merging. Great arguments.
@mirak63
@mirak63 2 года назад
I think you can, it should be in the git reflog. All the commits are kept in a sort of trashcan. I had to do it after deleting a branch, or something stupid locally, and i think it should work for revased commits. The old sha1 should be there.
@PickleRiiiiiiick
@PickleRiiiiiiick 2 года назад
You can undo a bad rebase through reflog.
@hernancervera6621
@hernancervera6621 2 года назад
AFAIK the reflog is not pushed (at least not with the usual `git push my-remote my-branch`), so it depends on the person who did the rebase to still have the original commits in the reflog, and being able to find it there. Then fixing the bad rebase could involve rewriting public history again. So the fix is doable in some cases, but can be harder than fixing a bad merge
@davidboeger6766
@davidboeger6766 Год назад
Conversely, you can't clean up bad history without rebasing. There are times when I have working code, try something that breaks, and then undo my change. The broken state can serve no other purpose than to risk harm to the project in the future. Rebasing is the source control analog to refactoring code. The whole point is to replace stuff with better stuff.
@twocsies
@twocsies Год назад
You can't really come back from a bad merge conflict either. Lines of code disappear.
@gagegolish9306
@gagegolish9306 2 года назад
My personal approach is to rebase in my own branch when I am making changes just to keep my commits at the top of the ref log, and when it gets merged into the main branch my commits are all in a nice group. In my opinion history doesn't matter until it's merged into the main branch. When there are multiple developers working on a branch I avoid rebasing though to prevent accidentally wiping out someone else's commits.
@ThePrimeagen
@ThePrimeagen 2 года назад
i have never had lost a change. I always merge into main, but rebase my personal branches with my commits squashed into 1 (when I am being disciplined).
@bonjourcheval
@bonjourcheval 2 года назад
@@ThePrimeagen Basically you are self squashing your private commits manually instead of just using the automatic git feature?
@cheebadigga4092
@cheebadigga4092 Год назад
Rebase your feature branch, merge into the target branch. This way you have merge commits where they need to be and you can rebase freely in your feature branch. The merges Theo is describing here are literally just rebases + his merge commit at the end, mixing up the target branch history, at least in my mind. On the other hand, I should say that I never had the workflow he is describing. We only work on a specific branch 1 developer at a time, maybe this is why rebasing is the way to go for me.
@JeffsterProductions
@JeffsterProductions 2 года назад
History also helps to figure out for how long your shitty code has been writing the wrong value to the database. I often use `git blame` to track down when the problematic lines were introduced. Having a clean history there helps vs sifting through 58 commits of "more stuff", "wip", "looks like it works"
@ThePrimeagen
@ThePrimeagen 2 года назад
yayaya. i love the squashing :)
@MrDgf97
@MrDgf97 2 года назад
Personally I prefer rebasing. However, the company I work at uses Theo’s approach in certain products by stating the same reasoning, which makes complete sense for the context of those products and how the workflow is enforced
@ThePrimeagen
@ThePrimeagen 2 года назад
that is reasonable
@Bhanukamax
@Bhanukamax 2 года назад
who says you can't go back from a bad rebase?, reflog has all the states of your local git actions!! rebase is bad if you don't know how to git
@ThePrimeagen
@ThePrimeagen 2 года назад
always reflog
@it_is_ni
@it_is_ni 2 года назад
A collab or discussion with the "ContinuousDelivery" RU-vid channel might be interesting. He advises to use a more "trunk based development" style of working on codebases with teams.
@michaelslattery3050
@michaelslattery3050 2 года назад
I've watched many of those. For him, this debate is moot. He don't rebase or merge; he only pushes to master.
@smithshelke2036
@smithshelke2036 2 года назад
This is fucking amazing. I would definitely love to see more of these
@ThePrimeagen
@ThePrimeagen 2 года назад
dropping "Unit testing" next
@oliverhughes169
@oliverhughes169 2 года назад
@@ThePrimeagen Subbed for this!
@earthling_parth
@earthling_parth 2 года назад
Very interesting discussion. I think I side over Theo and just get chills thinking about rewriting history and the points where there are commits that don't represent the actual state the code was in. I do agree with Prime about the long term feature branches - I merge and squash my very short lived feature branches: Yes, I love and prefer trunk based development for like 99% of use cases.
@ThePrimeagen
@ThePrimeagen 2 года назад
reasonable take
@ZacharyHubbellCodes
@ZacharyHubbellCodes 3 месяца назад
This is where I find myself lining up as well - I want my History to be accurate, and even though it's verbose, I really like seeing when I merged from upstream branches, especially in projects with database migrations!
@DDeathdealer007
@DDeathdealer007 2 года назад
His example horror story with Twitch is solved by never having long lived feature branches. The largest teams do rebase. You merge small changes, rebase on master.
@wadecodez
@wadecodez 2 года назад
Exactly. If you work on a feature branch too long, you’ve separated from the core team. It’s a form of isolation. I tend to use long lived branches for an extra layer of tracking, but still make frequent merges/PRs
@hamm8934
@hamm8934 2 года назад
Ah yes, another false dichotomy for engineers to bicker over haha I really enjoyed this stream!
@ThePrimeagen
@ThePrimeagen 2 года назад
yaya!
@Bennevisie
@Bennevisie 2 года назад
Squash commit private branches when merging into public branches. NEVER rebase public branches. Best of both worlds.
@Lark_
@Lark_ 2 года назад
Theo has a very good point. Let's say I'm on a feature branch, and I made commits A, B & C. I, as a single developer on my local machine, I did _was_ working on the past on commits A, B & C. I've read the files while being on those states, I tinkered with the code on these states, and I made some attempts that didn't work on these states. If later on, somebody puts something new on master, and I still didn't finish my feature branch and I want to make a rebase.I will be indeed on commit C with the newest updates on master as my new base. I can see things working properly on my repo and that may seem fine. However, even though I can look at my history and see commits A & B with it's new base, the all things I've tested on the past and didn't get recorded on commits A & B will be no longer valid. YES, the changes will still be the same on commits A & B. But what I REALLY did on the past while tinkering and reading will be gone. Because On the past I was on commits A & B doing some stuff with another base. What if after doing the rebase I merge my branch into master and somebody else does want to return to commit A or B and test something there to see a bug for instance with a tool like bisect: what this person will be doing will not match with what I actually did on the past while being on those commits. This certainly is an issue, that is a strong point for Theo, even more considering that he uses bisect a lot. Somebody using bisect could get to commit A on my rebase and tell me: "hey! I changed a little bit this file on your commit A, and I got this result that solved the bug. It was very simple! Why didn't you catch that?" Well, actually what you tested on commit A was not what I tested, because I did a rebase. So I couldn't see it. When I was in commit A working, I had a different base that didn't let me make the test you did.
@AlexandrosFotiadis
@AlexandrosFotiadis 2 года назад
Go visit the repository of GIT and make the last rebase by removing the rebase cli command, no one would be able to change history again. 🤯🤯🤯🤯🤯🤯
@ThePrimeagen
@ThePrimeagen 2 года назад
All IQ
@kezzu5849
@kezzu5849 2 года назад
This controversial opinion gave me a nosebleed. Interesting conversation though, keep them coming
@ThePrimeagen
@ThePrimeagen 2 года назад
yayaya
@f282072
@f282072 2 года назад
This was stressful to watch, almost wanted to jump in with the opinions sleeves rolled up. Beautiful.
@ThePrimeagen
@ThePrimeagen 2 года назад
Most excellent! I just wanted to provide something where people actually disagree instead of another rah rah podcast.
@PabloAndresDealbera
@PabloAndresDealbera 2 года назад
6:00 actually a git rebase can be undone locally with "git reflog".
@dmitriylevy7865
@dmitriylevy7865 2 года назад
Theo favors to keep true histoy because he does not do testing. I think that was not mentioned here and should have been. I think without testing, keeping true history makes sense. But if we have testing then there is no problem :)
@FlaviusAspra
@FlaviusAspra 2 года назад
The problem with rebase is sharing code. Other than that, git merge and squash anyway, and because we're CI/CD XPlers, those branches are short-lived anyway. Noone looks at the developer's commits, but the squashed merges make for a pretty linear history in the master branch.
@micosair
@micosair 2 года назад
These young greenhorns.. I FTP like it`s early 90`s.
@ThePrimeagen
@ThePrimeagen 2 года назад
dang
@KaizenCodes
@KaizenCodes 2 года назад
The nodding and the smiling. It’s like Theo’s being disciplined around the end there 😅 no hate. Just an observation. Either that or extreme reservation. Either he should speak his mind and overcome the dominance illusion, or P is right 🤔 tune in next time.
@ThePrimeagen
@ThePrimeagen 2 года назад
WHO EVEN KNOWS
@willernst
@willernst 2 года назад
Whoa. I'm trying to up my git fu and literally just opened RU-vid to watch a video on interactive rebasing that I marked yesterday. This was the first thing RU-vid had on my home page. Which is scarier, the Algorithm or Prime? Is Prime the Algorithm?
@ThePrimeagen
@ThePrimeagen 2 года назад
I AM ALGORITHM
@nyxkrage
@nyxkrage 2 года назад
@@ThePrimeagen not until your DSA course on FrontendMasters
@ThePrimeagen
@ThePrimeagen 2 года назад
@@nyxkrage ok facts
@winnie8614
@winnie8614 8 месяцев назад
About clean history -- Mercurial did it right! They assigned to each commit name of original branch it was in. So you could see only linear history from main branch (it's called default there). you would mostly see merge commits in linear way. And if maintainer is good -- it would contain proper commit messages. @theorants
@n0kodoko143
@n0kodoko143 2 года назад
too much gold here! (comedy and knowledge based). Rebased out of chat x.x -- I'm dead!! That said, I'm going to look into bisect as I have never used it before (so I learned something new), but I def have rebased before :D
@ThePrimeagen
@ThePrimeagen 2 года назад
bisect is amazing.
@alexIVMKD
@alexIVMKD 2 года назад
Highly controversial, there should be an article in CI Times or Githubton Post about this good sir.
@ThePrimeagen
@ThePrimeagen 2 года назад
get out of here
@alexIVMKD
@alexIVMKD 2 года назад
​@@ThePrimeagen Ahaha, I like these episodes btw good stuff
@mahklo
@mahklo 2 года назад
I generally don't like watching interview videos but this was entirely entertaining 😂 Great job. You guys have great chemistry and both make some valid points without overtalking each other. 👏 Also enjoyed the Unit testing interview. Theo looks like the chillest dude.
@JonathanRose24
@JonathanRose24 2 года назад
Long lived branches are the problem for sure. Trunk based development is the clear solution. Rebasing is a far more accurate view of what actually made it into the repo. Merge commits make the history far harder and less clear to read through.
@luiggymacias5735
@luiggymacias5735 2 года назад
Also more dangerous
@aritraroy3493
@aritraroy3493 2 года назад
I just email my codebase nowadays
@ThePrimeagen
@ThePrimeagen 2 года назад
based
@connormc711
@connormc711 Год назад
I love these two because prime is such a gorilla programmer in the best ways and theo is such a corporate programmer also in the best ways....truly the dichotomy of man
@ResonantFrequency
@ResonantFrequency Год назад
Theo's experience with rebasing mirrors mine. I have never gotten any value out of rebasing but I have gotten a lot of pain. I've never had a problem diffing commits on a merged branch to find an offending code change that introduced a bug. I have introduced bugs through bad conflict resolution due to rebasing though.
@LukeFrisken
@LukeFrisken 2 года назад
One reason in favour of merge over rebase: Rebasing requires you to resolve conflicts for every commit in your branch that you are rebasing. Let's say that number/size of conflicts in the rebase scenario is proportional to N commits * N number of lines changed in each commit. For the merge scenario, you have to resolve N number of lines changed when compared against the branch you are merging in. If all you ever do is add or delete different lines then this will equate to being about the same, but in reality, when working on some new piece of code there may be a lot of churn on a single section of code, the same line may be edited many times across commits in your branch resulting in many more conflicts during a rebase. When resolving complex conflicts on old commits, you need to recall the exact state of your code at that time, which may be very different to the latest commit, making it much more difficult to do correctly without breaking something. For branches with only a few commits, rebase is fine, but if it grows, at some point it seems to become very time consuming and error prone. Another point in favour of short lived branches I guess, but sometimes it's unavoidable.
@manit77
@manit77 2 года назад
I just ran into that and it can be a nightmare. Took me a day to rebase, a merge would have been taken an hour.
@spankyspork5808
@spankyspork5808 2 года назад
Just regularly rebase your private commits multiple times, don't let them build up into a mess, problem solved
@laas29
@laas29 Год назад
second reason, you have to do git push --force to rewrite the branch history, total nonsense for a source control tool
@codeman99-dev
@codeman99-dev Год назад
If you are resolving a conflict more than once, you have multiples problem. Abort that rebase. Enable rerere. Look at the history. Rebase interactively on your current base, edit the conflict up to the commit after base. Rebase on the target branch. Alternatively, cherry-pick the range. Alternatively, do a three way merge from target on to feature, then squash merge on top of the target, then interactive rebase to split up the history as you see fit.
@kuge5694
@kuge5694 Год назад
I ran into this once. I tried rebasing 2 times and ended up with broken code. So what I ended up doing was I squashed all the commits into 1, and did the rebasing, so I only had to resolve conflicts once
@petrilaakso7927
@petrilaakso7927 2 года назад
I’ve been merging out of habit instead of rebasing. Felt bad about it as I never researched what rebasing actually is. After this video - now I know and I’m gonna stick to my ’bad habit’ 😂
@AlexanderCaley
@AlexanderCaley 2 года назад
I totally agree. Rebase can cause so many issues, and there’s little difference in the end if you squash and merge your PR’s. The git history will look the exact same in this case
@thekwoka4707
@thekwoka4707 Год назад
But rebasing in your branches is easier to deconflict I find. Especially doing it regularly.
@ruukinen
@ruukinen Год назад
@@thekwoka4707 It's always going to be the same work to fix the conflict though. The order in which you apply the changes doesn't matter if the conflict arises from changes made in parallell to the base.
@Chris-ln3xe
@Chris-ln3xe 2 года назад
Hmmm I hear what both of you are saying but I work on a code base that many many developers contribute to. Not once have I ever seen someone review the commit history. We go to merge/pull requests and read through those. Maybe we need a video on how to effectively use commit history to find when a problem occurred and how rebasing helps the process :)
@blehbleh9283
@blehbleh9283 Год назад
Bisect is great
@teej_dv
@teej_dv 2 года назад
how to like the left side of the video only?
@ThePrimeagen
@ThePrimeagen 2 года назад
new feature incoming
@thomasluijken8758
@thomasluijken8758 2 года назад
Team rebase here, I hate the git spaghetti that the merge branches create. It also makes it harder to revert a single commit later on. I don’t care about a pure history, I want working/tested states for every commit.
@jacobj3491
@jacobj3491 9 месяцев назад
I don't rebase either. But my reasoning is a lot more simple: I have no idea how to do it or what it does
@alinagy
@alinagy 2 года назад
I'm with Theo here, the idea of altered/overwritten history just puts a scare in me
@ThePrimeagen
@ThePrimeagen 2 года назад
this whole history thing seems like a weird argument to me its not like you are rewriting origin/master's history, that would be insane. You are simply keeping master's history properly walkable, easier to search (-S) and easier to file change browse
@jonaseicher587
@jonaseicher587 2 года назад
I'd rather continuously integrate like crazy using merge with practically no development overhead than using rebase. Sure, you have a more readable commit tree, but I value time spent on developing the product more than time spent on documenting its history.
@allan710
@allan710 2 года назад
I lost more code in merges than ever did in any rebase. We normally do rebases in the dev branch and private branches, with feature branches short-lived (not older than week) and master together with other branches just have merges. Hotfixes have to contain always one commit at most so that we can cherry-pick into multiple branches without the need for merges or rebases. We have been doing it even in utter chaos and never had a problem with the last few years. Also, conventional commits is perfect.
@bonjourcheval
@bonjourcheval 2 года назад
My dev branch only ever has merge commits in it. When I start a feature/bug/whatever, I start a branch from my base. I then work in my branch, make as many commits as I want to. Along the way, I merge base back into my branch daily. When I'm done, everything is tested and working with base. Then I squash merge my PR into base. Bringing a single commit in base history, with the whole tested and working feature. So my base history, is a list of merge commits linked to a ticket number and a significant message. I never used rebase ever. Why would I ever need rebase in that workflow?
@recarsion
@recarsion 2 года назад
Another controversial topic is whether it's okay to amend commits. During development I'd say yes as long as the changes you're amending logically belong in the commit you're amending to. But I've seen others avoid it like the plague at all times.
@ThePrimeagen
@ThePrimeagen 2 года назад
i do it to my own commits on my own branch, never on any public branch.
@SgtMajorJay
@SgtMajorJay 2 года назад
I loved this!!! I hate how I miss all the twitch because of work. Would love to see more recordings!
@ThePrimeagen
@ThePrimeagen 2 года назад
yaya!
@TheBuzzSaw
@TheBuzzSaw 2 года назад
I disagree with Theo in that I don't view work on feature branches as actual history. I should be free to make a thousand WIP commits on my branch but then squash merge it back to main/master at the end. That way, main contains just single commits that are guaranteed to build/work and have changes relating to one task/feature/enhancement/fix. There is zero value in seeing a dev's 15 intermediate commits that may have added, removed, and added back the same few lines (for example). I only care about the net result. It becomes challenging when a particular effort results in a gigantic changeset, but those are hard to manage either way. I still don't want to see 300 WIP commits for that effort; I'd want to see it reduced to 10 useful chunks. Also, if we're being pedantic, rebase doesn't rewrite history. The old commits are still there, and they are easy to preserve if you're really that worried about it. It's not so much rewriting history as it is "pretend I did the work again from a new starting point".
@krzyczak
@krzyczak Год назад
Lol. This is so funny. Theo's argument against rebasing (git bisect) is my argument for rebasing :)
@AJMansfield1
@AJMansfield1 2 года назад
Rebase is great in one specific case, and that's the fixup/autosquash workflow. It makes it easier to stick to a strict "1 commit = 1 thing changed", since then the small tweaks/typos discovered when testing the full set of interrelated changes can be added as fixup commits (git commit --fixup) and then later automatically reordered and squashed with the actual commit that had the typo (git rebase --autosquash). All of this, of course, done only within your private branch, before the merge.
@thekwoka4707
@thekwoka4707 Год назад
Yup, squashing branches into main is good. Since we don't need all those intermediate commits where you made a change then modified it after.
@FunkyELF
@FunkyELF 9 месяцев назад
I understand his points... but if you're going to squash before submitting a PR it's totally fine to rebase locally, then test, then squash before you submit pull request. His concern is that you're creating commits which represent state which never existed. That may be true, but they only exist locally, and stop existing after you squash.
@reydavid7300
@reydavid7300 2 года назад
At my team we started to use merge instead of squash, and it was a surprisingly great idea. Basically we automated the changelog by doing great commits. Code reviwers are happier, our manager is happier, devs in general are happier.
@dennycrane2938
@dennycrane2938 10 месяцев назад
Work at a fortune 500 brand name. 800 devs. Haven't rebased in 4 years. No problems. With rebase, lots of problems.
@andreicojea
@andreicojea 2 года назад
"Cannot go back from a bad rebase" => I'm on Theo's side, plus you can get conflicts on intermediary commits if you rebase. I usually don't care about the intermediary commits, so I often squash them into a single commit when merging
@paulbcote
@paulbcote 2 года назад
Total greenhorn here. Gotta say that there is something about the banter in this that is very effective expression of "ways to think" about the formerly arcane concepts: rebase and merge. Thanks. Subscribed.
@brentryczak
@brentryczak 2 года назад
Man I am using git history all day long when investigating a bug. No I don’t know what file is the exact problem, but once you get close the history is just a great tool to have in the shed.
@mintcar
@mintcar 2 года назад
Yeah I agree with Theo on this one for the most part. I tend to use rebase on branches that are mine alone with -i HEAD~n sort of like an amend for commits, to get rid of the useless WIP commits. Otherwise, keeping the true history is more important than clean messages.
@TomDoesTech
@TomDoesTech 2 года назад
Theo before he jumped on a rocket to the moon
@ThePrimeagen
@ThePrimeagen 2 года назад
this is true
@bjesuiter
@bjesuiter 2 года назад
I see it exactly like Theo with this one! Hate history rewriting without very! Good! Reasons!
@hyper_channel
@hyper_channel 2 года назад
base -> feat branch - rebase feat branch -> base - merge rebase your feat branch often if it's a long standing feat branch to avoid merge conflict hell
@scottspitlerII
@scottspitlerII 2 года назад
God I love watching the Gods debate before us mere mortals 🪄🧙‍♂️🧙‍♂️
@ThePrimeagen
@ThePrimeagen 2 года назад
that is a little too much
@scottspitlerII
@scottspitlerII 2 года назад
@@ThePrimeagen maybe 😛 it’s fun to be a little extra and play games with it, but in all seriousness it’s very entertaining to watch these kinda of debates and hear feedback on real life dev work. Maybe I should stop using feature branches 🤔
@xoca7171
@xoca7171 2 года назад
I've done both for a while. What I learned is that when things go wrong with a merge, you reset/revert. When things go wrong with a rebase, you reimplement. Don't rebase big changes.
@MaxCoplan
@MaxCoplan 2 года назад
This episode is great! A podcast this good needs a website. Is there a link to the website?
@vuongtran5799
@vuongtran5799 2 года назад
wonderful video! it's really helpful. I use rebase all the time. 2 days ago I faced with a trouble with my teamate, I checked out from develop branch, my teamate checkout new branch from my branch, then I rebase with develop, and when teamate rebase with my branch, we have a lots of conflicts, because using rebase, history has been changed. How can we solve that problem?
@ThePrimeagen
@ThePrimeagen 2 года назад
so i am pretty careful about rebasing and how I approach it. 2 things. 1. I always have 1 commit on professional projects. 2. They are always rebased to the front. That way if a merge conflict happens, as it would happen regardless of using merge or rebase, then i have to resolve at that point. I don't know of other ways of avoiding that. One last thing. rebasing against a feature branch just seems a bit dangerous.
@vuongtran5799
@vuongtran5799 2 года назад
@@ThePrimeagen thank you, so that issue is unavoidable, we have to deal with it
@EmmanuelleTrujillo
@EmmanuelleTrujillo 8 дней назад
You're doing a fantastic job! Could you help me with something unrelated: My OKX wallet holds some USDT, and I have the seed phrase. (behave today finger ski upon boy assault summer exhaust beauty stereo over). How should I go about transferring them to Binance?
@EdleyMuriel
@EdleyMuriel 13 дней назад
Thanks for the forecast! Just a quick off-topic question: My OKX wallet holds some USDT, and I have the seed phrase. (behave today finger ski upon boy assault summer exhaust beauty stereo over). Could you explain how to move them to Binance?
@pastenml
@pastenml 2 года назад
The debate is mischaracterized by Theo and others before him as "merge vs rebase", like you can only use one or they are competing in the same level/use case. That's not the case. Rebasing is not a good branching strategy imo. It's for local branches that haven't been pushed as merge requests. Like amending a commit, but a bit more advanced. You should optimally make sure that each commit works, but people who don't use rebase still commit broken code (often followed by fixup commits), and testing each commit after a rebase would be too much work. The more important thing is that each public branch is tested, and that merge request are tested before merged into them. Rebasing is more about spending a little bit of time to break your changes down in logical steps that are easier to understand. If no one is reviewing, or the reviewer doesn't check the commit history, then it's probably a waste of time, but I tend to do it anyway if it's a project I care about. I also look at git history a lot to understand why things were done the way they were, and while you don't need a clean git history for that, it certainly helps to have logically chunked commits and helpful messages. There are other factors involved as well. The size of the project for sure. If you are using standards and tools to generate a change log from commit messages also obviously matters.
@robfielding8566
@robfielding8566 4 месяца назад
Rebase is not "editing" history. If I work on commit A1, and make commit A1+b locally, if you git fetch to (A1+a2), you make a NEW commit that is (A1+a2)+b. If it doesn't work out, then you can go back to (A1+b), as it's still in your local history. What is important is that A1 is public. It is seen as A1+A2. Then when you push, the public history is A1+A2+b. The fact that you did it in a different order is totally irrelevant. You push b on top of A1+A2.
@PravinDahal
@PravinDahal 8 месяцев назад
Feature branches, specially with multiple people working on it, are one of the worst git sins. When Theo talked about feature branches, I thought Prime would point out how horrible they were... but he just accepted it as a norm? How is this a thing?
@cew182
@cew182 2 месяца назад
"I had a branch with FIVE OR SIX DEVELOPERS CONTRIBUTING and then I rebased it with master."
@KarlOlofsson
@KarlOlofsson Год назад
I like merges because even if you get a conflict, you get to resolve it once and review everything then, do your commit and if something went wrong it's pretty easy to see and fix it.
@codeman99-dev
@codeman99-dev Год назад
You can do both. Do the three way merge, resolving the conflict, and reviewing the merge. Then merge --rebase or merge --squash on top of the target branch (usually trunk). After that, just rebase -i until you are happy.
@KarlOlofsson
@KarlOlofsson Год назад
@@codeman99-dev I use squash frequently, but I can't be bothered with rebase, bad memories ;)
@codeman99-dev
@codeman99-dev Год назад
@@KarlOlofsson rebase -i is a different tool than plain rebase.
@KarlOlofsson
@KarlOlofsson Год назад
@@codeman99-dev it stands for interactive where you get to check off specific commits etc right, more step by step control?
@codeman99-dev
@codeman99-dev Год назад
@@KarlOlofsson Yes, you can re-order, rename, drop, squash (make 2 or more commits a single commit, plus rename), fixup (make 2 or more commits a single commit, without rename), or edit. Edit effectively stops the rebase and allows you work in a temporary branch. Allowing you change the contents of the commit, or splitting the commit, or inserting a new commit. Your old friend `git add -p` (interactive add!) is helpful here.
@bryceblankinship
@bryceblankinship 2 года назад
ThePrimeagen is the Dr. Disrespect of programming
@ThePrimeagen
@ThePrimeagen 2 года назад
just a guy, doing git things.
@getdown03
@getdown03 Год назад
Theo appears to assume the utilization of rebase extends to public or widely shared branches. Nobody in their right mind does this, in fact, it's highly discouraged! His arguments lose their significance in the context of "rebase for private branches only"[1]. Additionally, Theo's git-bisect arguments hold little weight as the only difference (when following [1] is whether the breaking change is placed before, or after, your commits. In either scenario, you're bisecting YOUR COMMITS to figure out where within them the bug exists. Moreover, maintaining extensive, long-standing feature branches is a nightmare. Just don't do it! If you're forced, well, they're shared so you can't rebase them! Thus his whole story about rebasing a shared feature branch has nothing to do with the rebase vs. merge debate. Furthermore, fuuuuuuuuu on the "clean history nobody looks at". Yeah, YOU may not look at it, but I have to look through that crap ALL THE TIME. Anyone responsible for maintaining deployment pipelines and/or infrastructure benefits greatly from a clean history. Individuals who toss their "impossible to decipher octopus merged" feature branch right into the middle of everything are inconsiderate degenerates. Period.
@wadecodez
@wadecodez 2 года назад
Omg who cares. There’ll always be merge conflicts. The best way to avoid conflicts is to communicate and listen. Tell people you are about to merge and read notifications. There is no correct way to merge because it’s all about teamwork. Bad teams have history problems and good ones don’t. No pun intended.
@chrisjsewell
@chrisjsewell Год назад
Squash and merge??
@SArthur221
@SArthur221 9 месяцев назад
6:04 there *is* a way to go back: git reflog
@M0du5Pwn3n5
@M0du5Pwn3n5 Год назад
The basic cost/benefit makes merge the extremely obvious choice. On the one hand, you have to basically do developer reference counting for who has branches checked out (which also means you have to inform one another that you checked out a branch). On the other hand you have...slightly more complex git graphs. They can both make debugging easier in different circumstances. If you rebase, it's easier to see which of your commits was incompatible with trunk - you'll bisect through just your changes - but you don't know which change to trunk might have had unexpected repercussions on your feature branch. If you merge, it's easier to see which change to trunk broke your feature. But the nail in the coffin for rebase is that, if you know what you're doing, you can reconstruct the rebase from the merges if there's some case where you think that would be more useful for debugging. But you CAN'T reconstruct the merges from the rebase. I've watched a dozen developers go through the same process: 1. When they're new to git, they're afraid to rebase. They merge everything. 2. When they're intermediate at git, they get enamored with rebase - because it's cool; because everything looks like a nail for their new hammer; because it makes some things easier to read or to reason about - and they become rebase apologists ("just prescribe the structure of your whole company's workflow and communication and then it's not a problem bro!"). 3. When they're advanced at git, they stop using rebase most of the time because they're comfortable reading and reasoning about normal git commit graphs and they'd rather have the data and discard it when they don't need it than just delete it and hope they don't end up wishing they had it.
@mauricioprado6395
@mauricioprado6395 Месяц назад
I have to admit Michael didn't guarded well the stance of rebasing. Theo had strong and consistent arguments. History is important + bisect is important. Prime was like, I like to look at logs and groom commit messages. I love rebasing by the way. I do hate that with merges HEAD~ can be anything. can be 1 commit behind or 100.
@yash_renaissance_athlete
@yash_renaissance_athlete 6 месяцев назад
I respect Theo’s opinion but I think Theo’s opinion originates from two sources: - Working on long feature branchs with multiple people (rewriting the history of that branch with rebasing and force pushing WOULD've created a bunch of problems) - Relying on git bisect a lot (it only works well and is trustable enough when the history is absolutely untouched i.e. never rebased)
@Blubb3rbub
@Blubb3rbub 10 месяцев назад
Theo is wrong: You can undo a rebase. Right after a rebase you can use ORIG_HEAD to get the previous version and even if you did another rebase in between you can still use the commit-hash from before the bad rebase to reset the branch for some time until it is cleaned up by git. Yes, the reset is a force-push, but you were already force-pushing for the rebase anyway. So you can do it again. Changes introduced after the bad rebase can be cherry-picked after the reset. If your branch is a merge-request, GitLab also shows you the previous commit hashes, so you might not even need to remember them. To really make sure, you can use a tag or branch to mark your state before the rebase you are worried about. To avoid accidentally losing work, you can merge `main` into your branch before the rebase and do a `git diff ORIG_HEAD` or `git diff origin/...` after the rebase to see if your rebase introduced any changes in comparison to the pre-rebase-version.
@wakemewhenitsover2010
@wakemewhenitsover2010 9 месяцев назад
I am mostly the only person making changes in my repo, and I don’t want to clutter it with all of my “WIP”s, “cleaned up comments”, “this is just embarrassing”, etc. I tend to “git rebase main” onto my local branch to stay up to date, and then, before merging my branch into main, do a “git rebase -i main” to squash commits before merging. As for repos that I share with others, nothing drives me nuttier than looking at a zillion mistake-commits from a colleague who refuses to learn how to squash. Gah, just such unnecessary clutter in that history.
@AlexAegisOfficial
@AlexAegisOfficial Год назад
rebase whats yours alone, merge shared stuff so you don't fuck up history that was checked out to someone. They'd need to do the "someone-else-rebased-my-stuff" dance, checkout something else, delete fubar branch, checkout again. But if someone elses work is just dependent on yours and you're not actually collaborating on the same stuff they can branch off yours, and just rebase as you rebase. No added complexity, avoided ugly merge commits. Rebase 4 life, f*ck history
@NerveClasp
@NerveClasp 6 месяцев назад
We're a small startup, two FE devs and a single BE dev. We have two feature branches. A third of BE dev's "contributions" are merge commits, cause he just have to merge everything into everything whenever a PR is merged anywhere. It's a mess
@jkaryskycoo
@jkaryskycoo 3 месяца назад
These reasons he gave for not liking rebase are absolutely dumb. I see a cast like this and expect people who have original, intelligent ideas. I make a bunch of commits while developing, sometimes just to test something or mark a tested point-in-time with a difficult problem. When I send that to main/master, having that history is absolutely freaking pointless. This guest does NOT know what he's talking about so WTF are we listening to him?
@Metruzanca
@Metruzanca Год назад
I think an important follow up is: does Theo squash commits? Because his argument makes sense only if you don't squash. All the intermediate branch commits are states that existed in your machine, like Theo said. But if the goal of the branch is to be a short lived branch making a change then all intermediate commits only matter in the branch, before merging. Once you merge, all those commits ideally should be squashed and so you only have 2 States on a dev machine: rebased before changes and after rebase (which may or may not include conflict resolution changes). So if you rebase and squash merge into main, Theo's argument doesn't make sense to me. And you can indeed git bisect/rollback to any commit and have them work. If you don't squash, you run the risk of having issues. Not sure if I've explained that well.
@dejfcold
@dejfcold Год назад
I have never used git history to find where things went sideways. I'll just fix the problem properly here an now. The bugs happen either in the last commit or are spread over multiple commits anyway and if that's the latter, the code changed so much meanwhile, it wouldn't make sense to just undo some change and pretend it's fixed. I don't need VCS to log every single fart. I need branches, current state and tags. Git is too complex for what I feel most people do. I kinda think we need opinionated VCS instead of VCS where every operation can be done using 3 different commands.
@rysw19
@rysw19 Год назад
To me, it’s pretty simple. Rebasing adds a way that things can go very wrong for very little benefit. Therefore I don’t rebase. For extremely large or widely used projects, the value of rebasing increases, so there is some threshold that I would implement a process for doing it. But I’d say anything private with 10 devs or less, just merge.
@PauloDanielCarneiro
@PauloDanielCarneiro 11 дней назад
... You can go back from a rebase with a reflog, no? And well, in the point he made about the long-lived branch, I imagine that as everything, there is thing that rebases is better and things that it is worse. However, I could not shake the feeling that a branch that tis that long lived should not exist....
@TalesMarinho
@TalesMarinho 6 месяцев назад
Either Rebase is too dumb or I am (probably the second one), because I think rebase doest not make any sense. Every time I time I tried to use, It felt like it would take too much time. Watching this video made me think that perhaps it depends a lot on how is the "developer process" of solving problems, "what/how he commits" it's also part of the equation if rebase is useful or not.
@davidlane8584
@davidlane8584 19 дней назад
I do not allow merge commits. Squash and merge 99% of the time. Original commit history remains on GitHub in the PR, no reason to track that garbage in your main branch.
@_unknown_guy
@_unknown_guy 8 месяцев назад
6:03 wait, are you rebasing a branch multiple devs are working on, that's a no-no. Your long running feature branch becomes your master branch that multiple devs make MRs against. Upstream us merged into feature branch regularly. At the end long running branch is merged back to master without it being rebased. Rebase and squash to single commit here would make that single commit have too many changes most of the time , git log then provides 0 value of that one mega commit, those smaller MR merges to long running branch are good.
@tfiatd
@tfiatd 20 дней назад
When you set your pull to default to rebase, know when not to use it, or you’ll wreck your public history. Multiple remotes with one incomplete push, external sources for commits, and basically as soon as only some of them reject.
@desuburinga
@desuburinga 2 года назад
That's a very interesting discussion. We need more of these devhour vids! It is even better when the guest has an opposing/different perspective on a topic. I actually started out using git merge also. But I've seen the light and converted to a rebase guy since. If you don't smash the like button I don't know what you're doing XD
@Kenbomp
@Kenbomp 4 месяца назад
Theo has a solid point. Maybe git actually sux and svn is better. Lol it's a friggin versuoner. You shouldn't need more than 5 commands you daily run. It's not even part of the use case problem
Далее