Live data from Hacker News

Protected branches and required status checks

github.com

21–30 of 49 posts

Re: Protected branches and required status checks

#21
post #18

Does the "required status check" thing apply to `git push`, or just to the merge button on the website? If it applies to `git push`, how do you trigger a status check to run on your actual merge/rebase as made in your local client, which will almost certainly differ in SHA1 and may differ in content from the merge made in the PR?

> Does the "required status check" thing apply to `git push`, or just to the merge button on the website?

It applies to all ways of updating git: push, the web UI, merging, and the API.

> how do you trigger a status check to run on your actual merge/rebase as made in your local client, which will almost certainly differ in SHA1 and may differ in content from the merge made in the PR?

If they differ in SHA1 but not content, things will work fine. A protected branch cannot be updated to a git tree that has not been tested.

If your PR differs in content, clicking the 'update branch' button on a PR will make the merge commit and your PR's content the same, so a new CI run will apply to the correct content.

Re: Protected branches and required status checks

#22
post #6

As a mercurial user, how easy IS it to accidentally force-push in Git? You have to really go out of your way to do it in mercurial, and I haven't found any reasons to do so.

I use git heavily and haven't ever actually had to force-push. It means that something's gone wrong, and you should really understand what.

And especially, especially if this is a team branch. At least make a copy of the old branch with a backup name, so you can undo your damages easily. It takes like 1 second.

Re: Protected branches and required status checks

#23
post #9

A good fix is to religiously use `--force-with-least` rather than `--force`. Sadly because Git I know no way to make force-with-lease the default and make —force less convenient (outside of a `git force` alias, which isn't going to disable `push —force` so you'll have to train it into your muscle memory) force-with-lease checks that the actual remote head and the local one match before pushing, which prevents overwri…

I think the point is to protect a branch at the origin so that the mistake of using the wrong options doesn't cause damage. Training everyone on a team to do the right thing is good, but everyone is prone to mistakes (myself included, even after using git for years).

You'll get no argument from me there.

Re: Protected branches and required status checks

#24
Preventing force-push is only one small part of a good solution.

good solution:

1. create pull request which is automatically being tested by CI

2. instead of hitting 'merge', tell build bot to take pull request and merge it into temporary copy of master

3. if tests pass on build bot, it applies pull request to master (by pushing temporary branch)

4. never ever push to master yourself

This is also basically what http://homu.io/ does.

Re: Protected branches and required status checks

#25
post #6

As a mercurial user, how easy IS it to accidentally force-push in Git? You have to really go out of your way to do it in mercurial, and I haven't found any reasons to do so.

As a Git user, it seems Very Hard to accidentally force push: you need to add a command line parameter, and I was simply taught "Don't Do That". I've certainly never done it.

e.g.:

  # yes!
  git push origin my-feature-branch
  git push origin master

  # no!
  git push --force origin master
nsfyn55 makes a good point about protection from others, though. Maintaining my own fork, and using pull requests to the central repo, seems to help avoid others clobbering master, but that seems to be more of a reflection of my organization's Git workflow.

If your team treats Git the way we used to use Mercurial, where each developer will merge their changes into master and then push it, you're going to be in a WORLD of hurt. (It's likely we were doing it wrong there, too. I didn't really grok distributed source control until we moved to Git.)

If you use the Github Flow [0], the merging is done in the UI of your Github (or Gitlab/etc) instance, rather than directly with `git`. (I believe Atlassian's stash has a similar but slightly different recommended workflow.) The keys for us are:

  - One team repo is the "official" repo. (e.g., UI/foo-widget)
  - Each dev forks the repo, and pushes their branches on that fork 
    (e.g. gknoy/foo-widget:gk-feature)
  - Pull Requests are made from the dev's repo __to the official one__ 
    (e.g. from gknoy/foo-widget's gk-feature branch 
          to UI/foo-widget's master branch)
Some teams instead opt to have each dev make branches on the same (official) repo. I prefer the extra safety net of maintaining my own fork. If I were to mistakenly commit something (or merge something, or rebase something) incorrectly, and totally fubar my repo's master branch, and then push that up to my origin before noticing it, I can recover it easily (rename branches, checkout the commit that should be the head, re-push). Worst case, I can delete my fork and re-fork it. ;) If I were to do that on a repo that I have shared access to, I'd have much more anxiety.

Incidentally, I've made exactly that mistake (merged or committed something onto my local master, and then pushed it to my origin) TWICE, and caught when others have when doing code reviews. The first time, I panicked and deleted/re-created my forked repo. The second time, I fixed it by juggling branches, and it was substantially easier. (Slower: it took me ~20 minutes I think?) In neither case did my mistakes affect anyone else, though, since the repo I messed up was my own.)

This is, of course, based heavily on Github's suggested practices, since we use Github Enterprise at work. Were I using Stash or GitLab, there would likely be some changes, but I think the team workflow really benefits when you dive all-in on Git's distributed nature.

0: https://guides.github.com/introduction/flow/

Re: Protected branches and required status checks

#26
post #4
post #3

Gitlab has protected branches feature for quite sometime. I was wondering when Github is going to implement it. Finally!!!

The benefit of competition. I hope Gitlab, Github and others keep pushing each other forward. It's better for everyone.

We'll do our best.

It's a very interesting market. I think we're (we as in: GitLab, GitHub, Stash) all very aware of each others features and shortcomings, not in the least because of the intense comparison that every customer does before they decide on a purchase.

At GitLab a large part of our new features are driven by requests of customers or shortcomings that they noticed in competitors' products. In the end, we also believe this benefits everyone.

Re: Protected branches and required status checks

#27
post #21
post #18

Does the "required status check" thing apply to `git push`, or just to the merge button on the website? If it applies to `git push`, how do you trigger a status check to run on your actual merge/rebase as made in your local client, which will almost certainly differ in SHA1 and may differ in content from the merge made in the PR?

> Does the "required status check" thing apply to `git push`, or just to the merge button on the website? It applies to all ways of updating git: push, the web UI, merging, and the API. > how do you trigger a status check to run on your actual merge/rebase as made in your local client, which will almost certainly differ in SHA1 and may differ in content from the merge made in the PR? If they differ in SHA1 but not co…

Thanks! That's a very sensible model. I suppose it means that the status-check API can't be used to check that the history of a branch is up to some standards, like commit messages following a style or all commits in history passing some check, but that's fine. (It is a bit at odds with the documentation of the status-check API, which implies that it's about refs, not trees.)

Re: Protected branches and required status checks

#28
post #6

As a mercurial user, how easy IS it to accidentally force-push in Git? You have to really go out of your way to do it in mercurial, and I haven't found any reasons to do so.

> how easy IS it to accidentally force-push in Git? It's easy to accidentally force-push to the wrong branch . If you're on the wrong branch (e.g. you think you're on your personal dev branch and want to update it after a rebase but you're actually on the mainline) `git push -f` will ruthlessly clobber the remote.

Yep. I force push frequently to feature branches on my remote when preparing pull requests. Being able to protect against this on the canonical branches of the main repo is a nice addition.

Re: Protected branches and required status checks

#29
post #17

This sounds like the wrong solution to me. The problem isn't (or rather, is rarely[1]) that you've "polluted" a public branch with bad code. Bad code gets pushed into branches by perfectly legal commits all the time, and you fix it via software engineering and not administrative policy. The real problem with the accidental force push is that it's lossy. The OLD head, to which you would hope to revert when you realize…

> The real problem with the accidental force push is that it's lossy. The OLD head, to which you would hope to revert when you realize your mistake, is suddenly invisible (and garbage-collectible!).

I prefer how Mercurial behaves in this matter. A push can not destroy old heads, and the old (dangling) heads still show up in the log by default (you can filter them out with an option, if you don't want to see them).

So if someone pushes a new head by accident, anyone can still see what is going on, and fix the situation either by a merge, or reverting back to the old head.

(The downside is, if everyone really knows what they are doing and never make mistakes, git's way of deleting old heads with just a force push is easier, than needing to specifically access the repo on a server if you want to delete some heads.)

Re: Protected branches and required status checks

#30
post #17

This sounds like the wrong solution to me. The problem isn't (or rather, is rarely[1]) that you've "polluted" a public branch with bad code. Bad code gets pushed into branches by perfectly legal commits all the time, and you fix it via software engineering and not administrative policy. The real problem with the accidental force push is that it's lossy. The OLD head, to which you would hope to revert when you realize…

> Track the head of each branch at each point in "monotonic server time

oof talk about over-engineering. What is the point? Just don't allow force pushes to protected branches is a much simpler model than. "Keep a bunch of bookkeeping meta data in the event of an unanticipated force push". All this complexity would only save you during the span of time those objects were collectible but not yet collected.

Post reply on HN