Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Force a user to force update before commit

Gabriel Smith March 4, 2013

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

0 votes
KieranA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 4, 2013

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 Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events