how to place permanent hooks in .git file

hi ,

    i want to edit the .git folder inside the selected repo and i also want to push it to remote.

is it possible to do , if so plz help me to solve the issue.

 

Thanks & Regards

Shruti Muktedar

3 answers

1 accepted

Hi Shruti,

Balazs is right, you cannot automatically install client-side hooks for all users this way. But you may consider server-side hooks, especially update and pre-receive. See this documentation: http://git-scm.com/book/es/v2/Customizing-Git-Git-Hooks 

The downside is that your users might only realize that many of their commit messages are invalid when they try to push, and cleaning up dozens of messages might be a tedious task.

I recommend you to use a server-side (update or pre-receive) hook and an optional client-side pre-commit hook. Your users will happily install the client hook themselves manually if they want their lives become easier smile

------

Update: Our company (Midori) has released a JIRA plugin called Commit Policy Plugin for JIRA that makes managing centralized source code policies a breeze and it can help in the situation being discussed in this topic.

It allows you to build complex commit rules on the JIRA server via a nice UI and it also allows you to generate ready-to-use hook scripts utilizing these policies for Git (and also currently Mercurial and SVN) in a few mouse clicks. You can simply drop the generated hook script package into your Git central repo and start using it.

I recommend you to give it a try, it will save you a lot of work - I know it, I put that work into the code wink

You cannot put hooks inside the .git folder in such a way that they will apply to everybody who clones the repo, since the .git folder is not under source control. You can create a folder in your repo where you store your hooks and ask everybody to copy the contents inside the .git folder locally.

(Or install the hooks on the server only, so non-conforming pushes are rejected.)

hi ,

but i want to apply that hooks to all users, i have build some script for commit message , so i need everyone to use it. pl tell me from where that .git file comes, means in server where shall i change the .git folder so that it will be permanent in the every users .git folder.

This should have been written as a comment under the answer you are replying to, not as an answer itself.

You could create a .sh file (init-repo.sh) and tell new collaborators to run this script after they cloned the repo. Take a look at this: https://github.com/angular/angular.js/blob/master/init-repo.sh In the last line: echo "Installing git hooks..." ln -sf ../../validate-commit-msg.js .git/hooks/commit-msg

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

683 views 0 4
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