How to make a git repository read-only?

前端 未结 9 880
执念已碎
执念已碎 2020-12-02 15:09

I have some git repositories accessed remotely through SSH and I want to make some of them read-only to prevent more pushes. Some people have remotes pointing to these repos

9条回答
  •  一个人的身影
    2020-12-02 15:45

    A pre-receive hook that simply prints an informative message and exits with a non zero status does the job.

    Assuming you put some meaningful information in your message, it also cuts down on the queries from frustrated users asking why they can't push:

    #!/bin/bash
    echo "=================================================="
    echo "This repository is no longer available for pushes."
    echo "Please visit blah blah yadda yadda ...."
    echo "=================================================="
    exit 1
    

    Remember to set the executable permission for the script and to make sure is owned by the right user and/or group, or else it will not execute and will not give any warning.

提交回复
热议问题