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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

434 views 0 1
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