I want to avoid pushing multiple commits to remote repository. Is there a config option in git which will disallow or warn when multiple commits are being pushed to the remote branch?
-
Are there specific commits you don't want to push? Or you always want to push exactly one commit? If the latter, why?Chris– Chris2019-06-18 02:21:51 +00:00Commented Jun 18, 2019 at 2:21
-
Though rare, I sometimes need to revert some older commits to verify my current changes. This is suppose to be only for testing purpose only. After i'm done with the testing, I'm suppose to push just the top-level commit. But I end up pushing all. This has happened twice. I was just wondering if this could be avoided through a config knob. If not disallowing the push, a warning will be helpful.Pessy– Pessy2019-06-18 18:46:08 +00:00Commented Jun 18, 2019 at 18:46
Add a comment
|
1 Answer
I believe you can do this through a git hook, either pre-push on the client-side or pre-receive on the server-side.
You can see more about these hooks here: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
This has an example of how you might script this: Git hook pre-push prompt to squash commits first
1 Comment
Pessy
Thanks! I will take a look at this approach. I'd have preferred a gitconfig knob though.