Force a user to force update before commit

Even though they have been asked to update sourcetree before a commit they sometimes for get and it causes them to lose work and or mess up our git

1 answer

Hi there,

This shouldn't be a problem as if they try to push and new commits have been pushed to the remote since their last pull then git/hg will ask them to pull and merge changes before pushing, so they shouldn't lose any work. DVCS's are designed to do this specifically so you don't lose any changes.

You can set up commit hooks which perform some action before a commit. If you browser to ".git/hooks/" in your project directory there's a number of ".sample" files, you'd want to use the pre-commit.sample file and enter a git command in there which will get exected before they commit. Rename the file to just "pre-commit" once you're done and it'll be exected before the commit happens.

I wouldn't suggest this, however, because you shouldn't be losing any changes at all in your process even in your case. There are many times I attempt to do a push and changes have been pushed since my last pull, but I never lose changes because I'm now allowed to push until I pull and merge changes. Perhaps there's something else wrong with the process here - in any case, I wouldn't suggest using hooks to get around the problem you're having. It'd be good to know more about your workflow to find out why this is happening.

Cheers

Suggest an answer

Log in or Join to answer
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

274 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot