0

I would like to add .git/hooks/pre-receive hook to master/remote branch but .git/ will not be source controlled. How can I copy .git/hooks/pre-receive to master branch(server repository is configured on linux) ?.

Are there any configuration settings to ignore .git automatically ? Can I change that ?

.git/hooks/pre-receive should exist in master repository only as this is triggered by server when git push is executed.

Techie
  • 759
  • 4
  • 11
  • 29

2 Answers2

0

Due to security concerns, hooks are not managed in the git history (imagine that you clone a random project in the Internet which contains a malicious code in the post-checkout hook...). It is set by design and I' afraid it may not override.

If you require the pre-receive hook to be active in your server, you'll need to activelly configure it (either connecting to the server or using the interfaces provided by your server, if any)

Álvaro P.
  • 1,031
  • 9
  • 9
  • I am asking about that configuration settings only, if any. I could not find any way to add my hook to server. This is one time set up only. I should be able to put it in server `.git/hooks/` folder. – Techie May 29 '18 at 11:35
  • How is your server setup? Are you using gitlab, bitbucket, github (depending of your server, the solution provided by the developers may be diferent) or are you using a machine simply containing a bare repo? – Álvaro P. May 29 '18 at 12:33
  • My server setup is on ALM tool (UI based). When I go to code part , it is showing everything except `.git` folder. I need to add hook in `.git/.git/hooks` – Techie May 31 '18 at 10:04
  • usually, '.git' folder is hidden. Are you showing hidden folders in your UI? – Álvaro P. Nov 28 '18 at 11:22
0

How can I copy .git/hooks/pre-receive to master branch(server repository is configured on linux) ?

Log in to the linux server. Copy the file to the appropriate directory. If you need the transfer the file, use whatever mechanism you have set up for that purpose (ftp, ssh, file servers, etc.).

Are there any configuration settings to ignore .git automatically ? Can I change that ?

No. by design no part of the .git folder is shared by push/pull. That hooks are included in that is most definitely deliberate. It is not configuration; it is the design of git.

You might be able to confuse git by toying with the "git directory" environment variable in some way, but if this were ever shown to somehow write to the server's metadata directory, it would be considered an exploit - not a configuration change - and git would soon be patched to prevent it. (It probably already can't be done, but who knows what one might find prying at the edges of a system...?)

.git/hooks/pre-receive should exist in master repository only as this is triggered by server when git push is executed

Which as good a reason as any that you can't push it to the server; that implies it exists on the clients as well.

By the way, the source repository is conventionally called origin, not master. master refers to the default name of the default branch and exists in all repos. Although this is all configurable, using the terms in the conventional way is advisable to keep communications clearly understood.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • Thanks for your help and suggestions. First thing I do not have much idea about server side git repository that is why I am little confused about this. I am not able to copy file directly because we have a UI based tool(ALM) to merge the code. When I check the code there `.git` is not visible. That is why I am worried how can I copy it. I am searching about any commands which can transfer from local repo (as you said ftp, ssh, file servers, etc.) but I could not figure it out. – Techie May 30 '18 at 04:11