0

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?

2
  • Are there specific commits you don't want to push? Or you always want to push exactly one commit? If the latter, why? Commented 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. Commented Jun 18, 2019 at 18:46

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I will take a look at this approach. I'd have preferred a gitconfig knob though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.