Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Raw Git Server and Git Branch Restriction
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Raw Git Server and Git Branch Restriction

I have a git server installed in one of my vps. I access it like this:

ssh://git@MY-IP:22/opt/git/repo.git

I wanted to create git push restrictions on certain users to push to direct master branch.

!/bin/bash

#
#

if [ "$1" == refs/heads/master ];
then
if [ "$USER" != fahad ];
then
echo "-----------------------------------------------------"
echo "WARNING: You are not allowed to Push in MASTER branch !"
echo "-----------------------------------------------------"
sleep 3
exit 1
fi
fi

Here, obviously $USER is "git". So, how can i actually get it to work ?

Comments

  • Why not use something like gitolite which would handle exactly this instead of writing your own script? It's rather minimal.

  • @file said:
    Why not use something like gitolite which would handle exactly this instead of writing your own script? It's rather minimal.

    Ok, i have plan to do that. But i want a temporary solution of above problem. can you suggest plz ?

  • AbdussamadAbdussamad Member
    edited November 2016

    give each user a different copy of the repo and use pull requests to keep everyone on the same page? that's how it's supposed to be done.

    https://git-scm.com/docs/git-request-pull

    you can be the only one with write access to the repo on your server. so every PR goes through you.

    Thanked by 1obakfahad
  • Thanks Everyone. I was looking for something that doesn't exist. I need gitolite or install Gitlab.

    But the idea of making several copies and then pool request seems much more cleaner way. I am looking forward to that. Thanks again.

  • Well, you can implement things like what you want using the hooks git provide. The link I posted above explain hooks. For instance, at work we usually had restrictions to push to the master branch, as we required every commit to contain a reviewed-by tag.

    Anyway, depending on your specific use case, I'd suggest you go with gitolite/gitlab or other alike solution, if it solves the issue for you. I use gitlab myself and it's great.

    Thanked by 1obakfahad
Sign In or Register to comment.