Hacker News new | past | comments | ask | show | jobs | submit login

If you work with other people, this model doesn't work so well, IME.

In particular, rebasing is very hazard-prone if someone else may have checked out your branch.

If you're working on a feature that needs changes in multiple components and is broken without coordination, you may be working off the same branch, or have separate branches with inter-merges. Either way, rebasing will cause trouble.




In particular, rebasing is very hazard-prone if someone else may have checked out your branch.

That's why you never rebase a published branch. This is easier to manage if your team uses a central repository as the 'official' repository and everybody pushes and pulls to that one. Then you know that your branches in your local repository are not public, not published, and safe for history-altering workflows like rebase. It's only the branches that you push that you're not allowed to rebase, at least not prior to the last push.

If your team doesn't use a central repository, and you're pushing and pulling between all of your local repositories, then I'd suggest using a naming convention for branches to distinguish public ones from private ones. Eg: start your private branch names with "DEV_". If someone else pulls a DEV_* branch, then they should expect that its history might change and they'll have to deal with that when it occurs.


> That's why you never rebase a published branch.

My problem with that is my coworkers and I usually work on our own feature branch. Ideally I wouldn't push mine to the central repository until I'm done, so I can rebase on master without changing the public history, but at the end of the day I don't like to leave code only on my computer (what if my hard drive blows up??) so I push everything I don't want to lose.


Git is designed so that branching is cheap. Why not create your own development branch off of the feature branch? Then use the feature branch as an integration-only branch?


An alternative would be to push to a private repo, rather than the shared, central repo. Of course, this has it's own pros and cons.


I would take that one step further and never rebase any branch ever.


My team of 6 handles this just fine, we try not to have many people on the same branch, nor do we like to have branches that live very long. Merges of branches that are old tend to cause more problems. Problems that would have fallen out on the developer side if they had rebased.


I'm using this model in a team of 12, it works fine, except for: 1. needing to have reliable testing environments for QA/product people to try features, as many feature branches are worked on at once; and 2. new people having trouble with rebasing, or have to understand git just a little bit better than pull/push/commit.


> 1. needing to have reliable testing environments for QA/product people to try features, as many feature branches are worked on at once

Makes sense. Also, try using continuous integration (which should test every commit), and try teaching people to check out particular commits (by hash). I find that once people understand what "headless" means, and how to get out of it, `git checkout <commit hash>` is a very useful way to test _specific_ things.

> 2. new people having trouble with rebasing, or have to understand git just a little bit better than pull/push/commit.

I think the lesson here is that spending a bit of extra time teaching your developers (not to panic,) how git works, and how more obscure commands work, goes a long way.


> nor do we like to have branches that live very long. Merges of branches that are old tend to cause more problems. Problems that would have fallen out on the developer side if they had rebased.

This is a great point. Keeping branches small avoids serious integration problems.


It works well if you keep changes small. Basically if you're making a change that integrates with some other place that someone else needs to update, that looks like two separate changes to me. Of course you can do big feature branches that change a lot of things at the same time, but you're right - that won't work here.

Regarding big projects -> gerrit works pretty much the same way (but also forces you to squash changes into a single commit). This is used successfully by cyanogen and openstack people at least. Those are fairly big teams.


> gerrit works pretty much the same way (but also forces you to squash changes into a single commit)

That may explain why one of the committers I work with on an open source project heavily suggests squashing changes into a single commit when merging topic branches into master. He works with gerrit at his day job!

Personally, I think it's better to only squash experimental commits or minor stuff like removing a newline, and to keep development of a feature spread out over several commits if it makes sense. Makes it easier to revert back to a specific commit.


Your branches are private. Only public branches should be a considered for check-out.

Private branches can be rebased at will but the public branches are off limits. A public shared repository may help in this case.


I'm assuming a GitHub / Stash / similar workflow. Branches are not private; they are not kept just locally.

(By private, I mean unpublished, in such a way that someone may have merged or branched off my branch.)


If people pull from a random github branch I think it is their problem.

They should pull only from what you declare as public branches with stable history.

I keep on github only the master branch and publish the feature branch only when it is ready. After the maintainer merges the feature branch, I delete it from github.


I am, of course, talking about private GitHub repos used within a single company, and not about random people pulling down branches, but rather team development.


My point is that people should be branching from stable branches.

From your explanations, I understand your scenario is this: a private (shared by a team) repository on github. You work on your PC and then push on the shared repository on github.

If this is the case, you should push only when the branch is stable. If people really need those branches and you rebase them, you jut make it hard for them.

Either you stop rebasing what they consider public branches or you reconsider what are your public branches.


Oh, we don't have a problem, mostly because we stopped rebasing much. Which is basically my conclusion from the root of the thread.


This model works well for my team of around ~4 people. Not sure how it would scale to larger teams, though.


It depends on the complexity of the app as well, and how much vertical integration there is, and what kind of development pressures there are (in a startup, the deadlines can be very short).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: