Sazzad Hissain Khan
Sazzad Hissain Khan

Reputation: 40226

Git - Auto rebase while pushing

While working on a git project, I want to run a git pull --rebase before each git push. However, some developers in my team often forget to call git pull --rebase before pushing. So, Git/Gerrit automatically performs a merge which creates a malformed commit message.I want to avoid this auto merging.

I want to configure clients git so that when developers run a git push, a git pull --rebase should automatically occurs. Is there any way?

Upvotes: 5

Views: 2964

Answers (1)

merlin2011
merlin2011

Reputation: 75585

Tell all your developers to add the following to their .git/config files after cloning. Then require all of them to use git goodpush instead of git push.

[alias]
        goodpush = "!git pull --rebase && git push"

This configuration can also be placed inside the .gitconfig file in the user's home directory to avoid doing it for each repository that is cloned.

Note that the name of the alias cannot be push, for reasons discussed here, so you will have to provide some incentives or train your developers to no longer use push directly.

On the plus side, since you get a malformed commit message whenever somebody does use push accidentally, you will immediately know whom to speak with if such a use occurs.

Upvotes: 4

Related Questions