r/coding • • Aug 22 '17

You're using git wrong

https://dpc.pw/blog/2017/08/youre-using-git-wrong/
30 Upvotes

71 comments sorted by

58

u/ReginaldDouchely Aug 23 '17

Have you ever did a code review, and gave feedback that was longer than doing the fix yourself, while you’re at it?

Yeah. It's called being the most senior member of the team, and it's worth the learning opportunity.

23

u/beeglebug Aug 23 '17

100% agree. In my experience, code reviews are as much an opportunity for mentoring and personal development as they are about getting code into production.

4

u/DB6 Aug 23 '17

We use them also as a tool for knowledge sharing.

6

u/stinos Aug 23 '17 edited Aug 23 '17

Funny thing is, after coming up with this line (claiming it proves there is some kind of problem), later in the article the OP goes on telling how reviews should be done according to him: checking out the code, playing around, running tests, writing new tests. Urm, yeah, I completely agree that's how you properly review a largish patch, but: good way of contradicting yourself :]

-5

u/dpc_pw Aug 23 '17

I think you've missed the point. The problem is not being able to fix the code inline in Gerrit/Phabricator/Github code review UI, and having to describe required changes in a human language instead, then waiting for the author to implement them, and then having to double check if they were implemented like you wanted.

18

u/recycled_ideas Aug 23 '17

Which is intentional.

The point of a review is to transfer knowledge.

Yes, explaining to someone else how to fix the code is hard, but it's the entire point of the process.

-3

u/dpc_pw Aug 23 '17

The transfer of knowledge is very valuable. But very often the actual fix is a better explanation, than the description. To give a succinct example:

This method should be private.

is much longer to write and read than looking at the diff that is making the function private.

Or:

Here I have quickly changed your code to use an utility class Foo. Please use it next time.

is better than (obviously exaggerated):

Please use `Foo` utility class that you've never seen before. You might find some examples in a file `src/java/ourorg/module /submoduley/foo.java`, though it can be a little bit tricky. Just figure it all out. There's no documentation on how to use it yet. If you have troubles, good luck catching me between my meetings this week, LOL.

14

u/recycled_ideas Aug 23 '17

Yes it's shorter, but that's mostly because your code review comments are shit.

Why should the method be private?

How do they use utility class Foo and why should they use it.

In your solution the person asking you to review doesn't learn anything, so they don't stop making mistakes. Maybe they didn't use Foo because the documentation on how to use Foo or even that Foo exists is crap.

Them making the change is the whole point. It's not broken, it's supposed to work that way.

7

u/tonnynerd Aug 23 '17

It seems like you're assuming that the code review tool is the only communication channel. I don't know if there's any companies that do this, but where I work, the code review comments are supposed to be short pointers towards fixing the issues. If the author of the patch can figure it out on his own, great. If not, there's chat, email, and video conference channels that he can use to reach me. The author of the patch is not required to figure everything out from the comments. It's good if he can, but it's expected that extra communication will be needed.

2

u/millenix Aug 23 '17

In my organization, we kinda encourage people to keep as much of their communication as possible in 'structured' media, connected directly to the issue or code in question. This makes it much more readily retrievable by others who need to understand it later, and traceable to people who need to understand it while it's still in flight.

1

u/tonnynerd Aug 23 '17

I see your point. I guess it's a bit of a trade off, and depends on tools too. We use Gerrit, which sucks at pretty much everything. If we had a somewhat better code review tool, I could see how keeping more of the discussion there would be helpful.

In any case, we often have private discussions and then the reviewer posts a sort of summary of it in the review, to kind of document it.

1

u/millenix Aug 23 '17

We use Gerrit too. It sucks, but the alternatives all seem to be worse for us in one fashion or another. And even if something better were readily available, it would have to be enough better to warrant the transition cost of at least our ongoing work.

1

u/millenix Aug 23 '17

We use Gerrit too. It sucks, but the alternatives all seem to be worse for us in one fashion or another. And even if something better were readily available, it would have to be enough better to warrant the transition cost of at least our ongoing work.

6

u/Ansjh Aug 23 '17

Your exaggeration covers a bunch of different unrelated issues. Why not just say this, for example:

Please use the utility class Foo here, otherwise you're duplicating code.

Additionally, link to documentation as well. (If that doesn't exist, that's a different unrelated problem, and even in that case you could just link to the file/line of the class itself.)

6

u/cybernd Aug 23 '17

So your point is, that you are in favor of commit ping-pong over one developer having the responsibility of fixing his own mess?

21

u/PC__LOAD__LETTER Aug 23 '17

Interesting write-up, but I disagree.

There should be no “one master branch” that everyone uses, since it’s a point of contention and a single point of failure. And when stuff breaks in “one master branch” your whole organization is affected.

Where do you build releases out of?

Bottom-up: Junior developers should push their changes to senior developers, that truly review them (as opposed to just “glance over and point out mistakes” - more on it later), and if accepted, they include them in their own branches then push to team leaders, and then release managers and so on.

Oh, I see where you're going with this. Where do you think senior engineers are going to get the time to handle merge damage between two large changes by junior devs as they try to push into the release branch?

This might work for a group of people working autonomously on code that's very segmented and isolated. I'm not waiting on a coworker because of quirks in our VC system, I'm waiting on them because they're implementing some functionality that fundamentally changes the architecture of the code and my work will only really gain meaning once that context has been established.

or a developer to truly review a change, the developer should download it locally, do git checkout on it, open in IDE/text editor of their choice with or along diff viewer, jump around the new code, run tests and even write some new ones, toy with it, execute etc. Only then the change has been “reviewed” as opposed to “glanced over”.

This again sounds unrealistic. Although actually, where do you work that senior engineers have this much free time... ? Sounds kind of nice.

Review should be more about communication and collaboration, rather than just one way critique. If problems were found the reviewer can fix them immediately and send back the fixes.

Besides sounding extraordinarily inefficient with respect to the time of senior devs (I keep coming back to this because I think it's a critical flaw) and other gatekeepers, this is a bad idea because it destroys the virtuous feedback loop that exists as a result of senior devs imparting hints and general feedback as part of code and design reviews.

-3

u/dpc_pw Aug 23 '17

Please excuse brevity. I'm just short on time.

Where do you build releases out of?

Release branch maintained by someone filling the release manager role.

Where do you think senior engineers are going to get the time to handle merge damage between two large changes by junior devs as they try to push into the release branch

Typically if the conflict is small, you fix it yourself. If it's bigger or you don't have time, you pick one set of changes to keep, and tell the author of the other to rebase their work.

This again sounds unrealistic.

It really isn't. The degree of the review is entirely in reviewer's discretion. At a minimum, it can be "glancing over" as before.

1

u/[deleted] Aug 29 '17

Release branch maintained by someone filling the release manager role.

Which is the whole "throw it over the wall to the dev ops people" problem that dev ops engineers are trying to remove.

Releases should be done by anybody and everybody, not a designated "release guy".

28

u/leftofzen Aug 23 '17

There should be no “one master branch”

This is mostly bullshit. If there is no 'master' then how the hell do you decide which branch you release next? You might want to look at the linux kernel, for which git was created - it has a master.

Rest of the article makes bits and piece of sense.

I'd just love if my company stopped using TFS and got onto Git :|

1

u/recycled_ideas Aug 23 '17

You can use git in TFS now. Visual studio support is a bit spotty, but it works fine from the command line.

1

u/leftofzen Aug 23 '17

True and that's what I do at home, but at work they use the team foundation version control as well :|

1

u/recycled_ideas Aug 23 '17

There are worse things.

You could also use git TFS. I've not tried it for anything but migration, but it works.

1

u/[deleted] Aug 29 '17

It's still got a lot of problems, lots of failed gets, failed pushes. It's not that cleanly integrated.

1

u/recycled_ideas Aug 29 '17

Using the command line git client I've never had a single problem.

The UI on visual studio isn't great, especially if you're not using the latest and greatest. Mostly because it doesn't really give you good feedback when you've got a push or pull that fails due to unmerged changes.

-2

u/dpc_pw Aug 23 '17

There is Linus Torvalds master branch which is considered official Linux kernel master branch, but people routinely cooperate and work on top of other branches for long periods of time, before their work reaches Torvalds' master.

4

u/MuonManLaserJab Aug 23 '17 edited Aug 23 '17

But there still obviously is a One True Master Branch (Linus'), and if it's broken, lots of people would have problems.

Is the point here that not every Tom, Dick, and Harry should be allowed privileges to commit to this privileged branch? Because if so, that's not well-communicated.

The article says not to have a single point of failure, but then it also acknowledges that at some point everything has to be put together into a single release branch -- one point of failure. It doesn't explain why one point is more failure-prone that the other, and it handwaves the complexity involved in sharing code sideways while overstating the complications of having a single code-review process (etc.).

Also, git works perfectly well as a CVS. You don't have to clone the entire history, and you don't have to clone the entire codebase if you break it up neatly. As the article says, why learn two tools when one will do fine for both cases?

Lastly, sorry if it's not your first language, but if you're not trying to say "you should always do it like this", you should probably find a different way to say it (rather than saying "I am just explaining what I mean", which is a meaningless non-answer).

1

u/Shikadi297 Aug 23 '17

Sounds like you're trying to make a distinction where there really isn't one... People make branches in SVN to work on things for a while before merging to trunk, it's the same concept in git except that it's much more flexible and reliable.

6

u/jonyeezy7 Aug 22 '17

Very interesting read. If this was on Medium, I'd give you claps.

Did you ever had a fix that your colleges are waiting for

That's what I've encountered alot.

Maybe i still can't picture the whole DVCS. But it seems that would still be a problem. If I'm waiting for someone who is making a big change on the exact codebase I'm working on, the distributed way would not fix it as I'll still have to wait for the PR.

Bottom-up seems bit too heavy for my scenario personally. We don't have a release manager. Everything is on a continuous deployment. So this kind of heirachy approach sounds slow.

I love the idea of across. And totally agree we spend so much time being pedantic in PR rather than the outcomes. Wish we could all do PR that way. We usually deal with 2-5 PRs in one day and relying on all reviewers to do the in-depth testing will be a big overhead. But i guess that's the pace we've set. But wish we could go down the approach you mentioned.

I reckon the mindset of a DVCS can still be applied to the concurrent model, ie across and bottom up.

Good article.

1

u/dpc_pw Aug 23 '17

Thanks.

Especially for smaller (like, let's say < 10 people team), there's not much hierarchy to build for the bottom-up direction to make any difference. I'd say 10 people is a group that could have a leader, and then 10 groups builds a higher level group (100 people), and then another level would be 10 groups like that (1000 people total). Obviously in the real organization, the groups would be more functional, not just equally sized and artificial.

7

u/Jestar342 Aug 22 '17

PRs aren't a git thing. There's no git pull-request command (out of the box). pull requests are just an organisational thing.

It is far more common for an org to use a central repo - yes, even when using a DVCS like git - as it just makes so much more sense to have one repo that is the source of truth. Hell, even when using pull requests and other management tools it's a safe bet there is a central repo. After all, the build has to come from somewhere and it's just logical to keep building from the same repo.

13

u/flukus Aug 23 '17

1

u/Jestar342 Aug 23 '17

Yes, which is very different from what people assume a pull request is (a la github with all the tooling github provides):

Summarizes the changes between two commits to the standard output, and includes the given URL in the generated summary.

In other words, it's a patch file and a URL.

1

u/andschwa_ Aug 23 '17

In a DVCS system you'd literally just apply the patches your coworker is working on, directly, skipping the centralized repo.

2

u/Volt Aug 23 '17

I feel like this workflow is more natural for something like Darcs. Git's model and the way people interact with it makes it more likely that they'll end up pushing to a central branch rather than sharing patches.

-1

u/dpc_pw Aug 23 '17

That's an interesting observation. Unfortunately, I worked very little with Darcs.

I, however, do notice, that git infrastructure (having to expose a http/ssh endpoint reachable over the internet), etc. favours centralized solutions like Github, and central internal infrastructure.

It seems to me that Git over DHT, or IPFS/Maidsafe, etc. would lead to people doing more things localy and such workflow being better supported.

2

u/AndiDog Aug 23 '17

This article states that all companies are equal and are working on a big product like Linux where the release branch must be heavily guarded, similar to how Windows core/kernel patches (allegedly, from what I've read, cf. http://blog.zorinaq.com/i-contribute-to-the-windows-kernel-we-are-slower-than-other-oper/) have to bubble up/along a hierarchy of approvals and test phases before getting merged for the next Windows update. Also you're shouting at all code review systems as if you've seen all of them. My company's, Phabricator, is pretty darn good and also used by LLVM, FreeBSD and other Linux-like huge projects. Its UI is awesome and we have adapted our workflow to automatically force-push a branch that matches the review (upon creation/update of the review, btw also a built-in feature of arcanist) so people could just check out those changes in git. Problem solved. So, the stereotypes from the article seem to be mostly void and there are lots of companies who have solved them well (and lots that haven't). I'd love more companies share openly how they work in an agile manner - having to wait the team lead and release manager before deploying a change is far from "agile" and should not happen in 2017 (except for... drumroll... Linux, where it makes sense!) and would be depressing for developers and take responsibility off them which they are finally getting with the devops [my mobile keyboard auto-completed this to "devil's" 🙄] movement.

P.S. since I'm already giving honest remarks: lots of typos and grammar mistakes in there (colleges vs. colleagues and so on)

2

u/max630 Aug 23 '17

automatically force-push a branch that matches the review so people could just check out those changes in git. Problem solved

Does this assume that the code is not pushed anywhere until it passed the review (so that people can check it out)? If it were there would not be even a problem to solve. You could even make CI run test and build artifacts to try manually before it gets to human reviewer to waste their time on broken stuff

1

u/AndiDog Aug 23 '17

Yes, we do code review before merging to develop/master (we use Git Flow branching model for reps that have releases). Also, an automatic builder picks up the review code and on build/test failure, an e-mail is sent to subscribers of the review. These kinds of automatic build are supported by Phabricator directly - we just had to integrate it.

-1

u/dpc_pw Aug 23 '17

This article states that all companies are equal

No, it doesn't. Obviously, I can only speak about my experiences and experiences other people shared with me, but I don't say that every company/organization is like that. If this article does not apply to you, good for you. :)

I worked with Phabricator before and I dislike it. And that's kind of the point. You and me don't have to use or be efficient with the same tool.

4

u/stinos Aug 23 '17

No, it doesn't.

No it doesn't state this explicitly, but after reading through it that is the impression it left with me "hey guys, look, kernel uses X and X is awesome becuase Y and Z and if you're not doing it like X then probably you're doing it wrong". Well, if I'm not at all like X, then that logic might be flawed.

1

u/dpc_pw Aug 23 '17

Well, I'm a rather poor writer and English is my second language so I might have failed to give the right impression. Sorry. :)

Anyway, I'm totally fine with being wrong and/or people having different options. Please don't read it too personally, and maybe you'll find something useful anyway.

3

u/stinos Aug 23 '17

Well you make some good individual points, but the "you're doing it worng" and "you have a problem" etc is a bit too strong and put too general.

Surely you'd be able to find a company which perfectly fits all problems you describe and which would hence be doing it wrong, but there are way more git users/companies out there for which it doesn't all apply.

61

u/Jestar342 Aug 23 '17 edited Aug 23 '17

I think you may have got the wrong end of the stick about the Linux Kernel "flow". There is a single master branch, but it is heavily guarded. Only Linus (and a select few) have access to it, but there is still only one true repo that the kernel is published from. origin/master.

How changes get there is covered well by your article - people push their changes up "the ladder" until it gets into this master branch. But this rigid security model does not suit everyone.

My team, for example, are 3 devs + a CTO that dabbles from time to time. We are all full time remote workers from all over the globe so pushing/pulling from one another is just impractical, and we don't have time to be reading and reviewing each other's code all the time.

What git does allow us to do is manage our changes via branches, stashing, etc. that traditional CVS (SVN, in our case) doesn't do well. For example in the case of an emergency patch for live, I can quickly checkout the current version into a new branch, make my change, push, build, deploy, and merge back into master a lot easier and more efficiently than SVN ever could.

Or if one of us wants to have a stab at making huge sweeping changes across much of the code base (such as a different ORM or changing from MVC to MVVM, or whatever) it's very nice having versioning that allow me to locally track my changes without needing to push/publish my changes for everyone.

0

u/[deleted] Aug 23 '17

[deleted]

1

u/Jestar342 Aug 23 '17

That image you are promoting as an image of distributed repos is nothing of the sort. It's a graphical representation of commits (see: gource) and the tree represents file paths from a single repo (note the url at the base of the image.. that's also the single repo in question!)

Whatever gets released as the linux kernel has come from that one master branch.

0

u/[deleted] Aug 23 '17

[deleted]

1

u/Jestar342 Aug 23 '17

Just to be clear, I am not saying the linux kernel is developed on a single repo. I am fully aware that people are making copies (forking) their own repos to make changes. BUT I am saying that all changes that make it into the kernel release(s) are eventually pushed back to TheOneTrueBranch™

0

u/[deleted] Aug 23 '17

[deleted]

1

u/Jestar342 Aug 23 '17

Which is completely beyond the point. What Linus Torvalds releases as the Linux Kernel always comes from that "vanilla" branch. Gentoo have their own, Ubuntu have their own, whatever. That's so beyond scope I can only surmise you either don't understand product management or are desperately clutching at straws. I'm not going to argue this anymore. There is a single master branch for what Linus Torvalds and the Linux Kernel group release as his/their product, which is complete affirmation of my point. What others do with that after the fact is not relevant.

9

u/LaceySnr Aug 22 '17

Interesting read, but FWIW I believe most organisations that do have one master branch do so because it's part of a CI process, and there is always "one version" of the code that is built to become the current version of the product.

Definitley depends on your use case though, perhaps you're not building a product and just working on an internal tool, where people do want to run different versions with different features.

7

u/cybernd Aug 23 '17

Lots of half-knowledge given your provoking topic title.

9

u/[deleted] Aug 23 '17

Am not.

4

u/FUZxxl Aug 23 '17

Just because git has all these options doesn't mean that you are doing it wrong by not using all of them at the same time. Every project has different demands and for many a "use git as if it was CVS" approach is just right.

1

u/dpc_pw Aug 22 '17

I hope this is related enough for r/coding since it does not have a single line of code. I'm looking for feedback and opinions.

3

u/andschwa_ Aug 23 '17

You're preaching what I think many of us are screaming inside at our coworkers. Also, I caught a few grammatical mistakes:

You have one process that everyone have to follow

has to follow

Have you ever did a code review

done a code review

Have you ever were unable

been unable

not relay on a central testing system

rely on a

3

u/dpc_pw Aug 23 '17 edited Aug 23 '17

Thank you! Should be fixed now.

0

u/[deleted] Aug 22 '17

[deleted]

1

u/dpc_pw Aug 23 '17

Hi.

Obviously, there are organizations with 100, 1000 or more people working on top of "one master branch" and doing fine. My point is, that git doesn't have to work this way, wasn't created to work this way, yet it seems to me people overlook or forgotten about DVCS approach, and so that is an approach I'm trying to describe by saying "you should this, you should that".

I assume the reader is somewhat familiar with "one master branch" approach, so I'm not elaborating on how that works or could be improved - there's plenty written on it already. (If I was to write about it, I would definitely talk over bors/homu etc.

3

u/EnergyCritic Aug 22 '17

I dunno, the post didn't read like that to me at all, and everything OP is suggesting flies in the face of what I currently practice and preach. It was a mind opener for me. I guess I don't completely understand why you are being so defensive about his writing but it is good to me

-3

u/DoctorOverhard Aug 23 '17

did you switch from cvs/subversion/clearcase to git? Or did you just inherit git and don't know how it got that way? This is about git, not you fwiw.

7

u/max630 Aug 23 '17

in general, I like your attitude, but there are 2 things:

  • the longer you develop separately, the more merge conflucts you get in the end.

  • there are many people around which are eager to have "clean" (meaning linear) history

1

u/akkartik Aug 23 '17 edited Aug 23 '17

That's the beauty of it: each of the decentralized repos may have mostly linear history. It may just be different linear histories.

Your first point is valid. I think truly decentralized development works for the Kernel for two reasons:

  • Many (speculative) branches are never ever merged.

  • Distant parts of the distributed network tend not to be modifying the same parts of the codebase (and then both getting merged).

Hmm, now I'm imagining a global view of the decentralized network that can track hot spots in the codebase that are liable to cause friction. That would help people touching those parts realize that some situational awareness would be useful.

1

u/jazzamin Aug 23 '17

Not quite what you want but for inspiration Gource visualizes the history of a git repo.

1

u/madou9 Aug 23 '17

Gave it a read. Good points about code reviews that could be implemented regardless of trying to follow your other distributed ideas.

Tbh I've always been a fan of grabbing two people and having a code review session in a room, go through the code, demo it, and make changes as needed in the spot. Much better than the delayed bullshit that is web UI, request changes, and delayed responses.

1

u/dpc_pw Aug 23 '17

Tbh I've always been a fan of grabbing two people and having a code review session in a room, go through the code, demo it, and make changes as needed in the spot.

Me too. Unfortunately, it gets harder in bigger, busier and/or somewhat remote teams.

2

u/Vi0lentByt3 Aug 23 '17

TL;DR I disagree with your article and think that you have confused the fundamental aspects of collaboration and general software development in a large organization with just the overall pain of having to do quality work.

I would like to know what you propose when you make these points:

  1. have a repo per project or mono repo? you have just described the only two scenarios that you could have in repos and projects together, so what is the third option?

  2. one repo per branch? this is very common in git and considered its main advantage where each person can holistically make changes completely isolated from anyone else's changes, not using this feature is closer to a CVS.

  3. one process for code review helps standardize the code and helps to ensure it conforms to the goals of your team i.e. the qualities you want for your codebase.

It would appear that you are confusing the fundamental components of git and collaboration in general that you simply cannot bypass no matter what tool you use. You still need one central point for all the code to live because that is your application.

The autonomy of a distributed model comes in the form of being isolated from the changes made to the codebase that you have to deal with in CVS systems, in git you only bring in the changes you want. The problems you state with code reviews taking too long, there overall process, and the tools available are things you will face at any organization. Code review tools allow for a historical reference outside of the codebase without having to use version control because version control does not care about code reviews, it cares about change management. Errors in the branches(bugs are not mistakes! See JBrains talk on integration tests) are usually from poorly written code and testing, not your version control.

If changes should start from the bottom up, where do they go? how can everyone's code converge and be combined if its not going to a central location? how do you have multiple branches deploying to a single unit of software(I understand if you a modular system this would be okay, but sometimes you need a monolith, ie a kernel). I do not think git propagates any of the problems you mention in the article, in fact it usually helps most of them. I think if you isolated all the issues you talk about and really look into their root cause, git would rarely, if ever be the culprit.

3

u/agentwiggles Aug 23 '17

I like this article. Some good points that definitely go against the common wisdom.

1

u/[deleted] Aug 23 '17

Should have gone for the throat, and done a complete, "My name is Donnie, and you suck at Photoshop," for programmers.

1

u/theclaw37 Aug 23 '17

These kinds of posts should be in /r/programming not /r/coding FFS when will people stop

1

u/QAOP_Space Aug 23 '17

things directly related to the actual process of programming - libraries, tools, and so on - are all okay, but please use discretion.

sidebar: "things directly related to the actual process of programming - libraries, tools, and so on - are all okay, but please use discretion."

0

u/theclaw37 Aug 27 '17

This post is not about how to use git, it's a rant about git users

1

u/paul_h Aug 23 '17

What do you think of trunk based development, Dawid? And also take a look at the "branching model" row of the PDF link to from https://devops.paulhammant.com/trunk-correlated-practices-diagram/

1

u/[deleted] Aug 23 '17

My reason is that I can easily cherry pick commits.

1

u/millenix Aug 23 '17

This article misses a fundamental advance Git offered over most other VCS systems from the time it originated: ignoring all of the actually distributed features, git merge actually works competently and produced more sensible results than anything else available. It made divergent development that was eventually intended for integration not as much of a terrifying prospect of merge conflict hell. Even an organization whose development practices are fully centralized would still gain a huge benefit in using Git over CVS or Subversion or Clearcase just from that. If "leveraging unique benefits of Git" is "using it wrong", you need to work on your definitions.

0

u/DoctorOverhard Aug 23 '17

well if it is a business, probably sarbanes oxley did as much as anything to keep things top heavy, which is to say it did no good whatsoever.