2

so let's say I have two branches develop and feature, and feature branch is ahead on two extra commits.

I'm looking for some kind of following behaviour

$ git checkout develop
$ git merge feature
Error: make sure you squash all commits in `feature` branch before merging it

Maybe it's possible to configure on github side? To make github reject git push origin develop when develop has couple commits from feature branch.


To make question more clear I will provide an example.

// 1. working on a new feature
$ git checkout -b feature
$ git commit -m "foo"
$ git commit -m "bar"

// 2. merging to develop
// here I supposed to do `git rebase -i develop`
// but I forgot!!!!
$ git checkout develop
$ git merge feature

// 3. push to github
$ git push origin develop

I wish I would get some warning on step 2 or step 3, because I forget to squash commits

2 Answers2

1

I would assume the correct way to do this in github is to use pull requests and only merge the ones which look correct. I dont know if github allows pre-receive hooks, but a standalone git will, and for others you might try Gerrit.

You CAN make a local prepush hook, but since it runs on the committers computer, it is trivial to avoid.

This gives you pointers on how to do a local check before merge.

How would I write a pre-merge hook in Git?

Community
  • 1
  • 1
Markus Mikkolainen
  • 3,397
  • 18
  • 21
  • yeah, we use pull requests. But I would like to ensure that committer will squash commits. In particular case I wish to be sure that **I** don't push some rubbish _(like sequence of `wip` commits)_ to remote `develop`. I will take a look on `prepush` hooks. – Liubomyr Mykhalchenko May 03 '16 at 18:38
  • yes prepush will disallow it ,but it will not prevent the user from making the error in the first place. – Markus Mikkolainen May 03 '16 at 18:40
-1

use git rebase -i develop. Then you will be able to squash commits.

Dmitry
  • 57
  • 7