search

Home  >  Q&A  >  body text

Prevent branch switching on git server

Problem scenario: The git branch on the server is master, but sometimes it may be mistakenly switched to another branch (but this is not the focus of the problem). I just want to ask the master if there is any way. The default is the master branch on the server. When using git checkout to switch to other branches, you will be prompted to enter a password.

PHP中文网PHP中文网2834 days ago681

reply all(2)I'll reply

  • 迷茫

    迷茫2017-05-02 09:46:46

    I guess you deployed it directly using git, not the situation of building a git server as @xiaoyao9184 said.

    The simplest violence is to make .git/HEAD unmodifiable:

     sudo chattr +i .git/HEAD

    But no, although the branch cannot be changed, the file will still be checked out.

    Or you can try post-checkout hook. After checkout, check whether it is master, and if not, switch back.

    If it doesn’t work, just fork a git.

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-02 09:46:46

    Don’t think about it, the server is a bare library, there is no concept of switching branches, gitlab can only protect illegal submissions from branches, and the permissions are accurate to the library level

    reply
    0
  • Cancelreply