0

I want to create a server-side git hook to block direct push to remote main branch. I look through some blogs and find it can be done by creating a .git/hooks folder and put a script named "update" within that folder on remote repo(Refer to this link).

Firstly, I try to push local .git folder to remote repo. But even with command git add .gitand confirm .git is NOT in .gitignore file, it has not been push to remote repo with regular operations. So my questions is how could I create .git folder in remote repo and put some scripts into .git/hooks subdirectory?

  • 1
    Does this answer your question? [Putting Git hooks into a repository](https://stackoverflow.com/questions/3462955/putting-git-hooks-into-a-repository) (In short, the way you suggest is not not how you do it, and yes, it does make it annoying.) – msanford Jan 21 '22 at 21:00
  • I looks through the post you give bt can't find the desired answer. Let me explain a little bit. Currently, I do have a remote repo without .git folder. And I want to add .git folder into remote repo so I can add hooks into .git/hooks folder, thus it can run on server side. But it could not be created by pushing a local .git folder to remote(at least from what I tried).. – Xiaoming Liu Jan 21 '22 at 21:43
  • 1
    You cannot push `.git/` folder with `git` commands. And you don't need to. Init a new git repo at the remote side using `git init`, then push your branches, commits and tags. – phd Jan 21 '22 at 23:56
  • 1
    @XiaomingLiu I know that's what you _think you want_ to do, but you cannot. The linked post is the way to get your hooks into git, and you must then have your users install them. – msanford Jan 22 '22 at 03:29

0 Answers0