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

how to place permanent hooks in .git file

ShrutiM April 12, 2015

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

2 votes
Answer accepted
Gabor Nagy [Midori]
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.
April 12, 2015

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

2 votes
Balázs Szakmáry
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.
April 12, 2015

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.)

0 votes
ShrutiM April 12, 2015

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.

Tim Crall
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.
April 13, 2015

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

Joberto Diniz April 13, 2015

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

Atlassian Community Events