I have an idea of locking a repository from users pushing files into it by having a lock script in the GIT update hook since the push can only recognize the userid as arguments and not the branches. So i can lock the entire repo which is just locking a directory.
Is there a way to lock a specific branch in GIT?
Or is there a way an Update Hook can identify from which branch the user is pushing and to which branch the code is pushed?
In your project, select the "Settings" tab on the far right of the menu. In the menu on the left hand side of the "Settings" page, select "Branches". Under the "Protected Branches" section, select any branch you wish from force push and deletion. Thanks!
In this article, I will show how you can protect your git branches and restrict them by implementing the best practices. Open your Master branch. On left hand drop down, you can see only Master branch. Start typing “stage”, and it will give you an option to create that branch.
Pick the file you want to lock. Click the “Lock” button. To lock an entire directory, look for the “Lock” link next to “History”. After you lock a file or directory, it will appear as locked in the repository view. Once locked, any merge request to the default branch will fail to merge until the file becomes unlocked.
Local branches are branches on your local machine and do not affect any remote branches. The command to delete a local branch in Git is: git branch is the command to delete a branch locally.
Although multi-branch file locks can be created and managed through the Git LFS command line interface, file locks can be created for any file. To list all the files locked with LFS locally, open a terminal window in your repository and run: The output lists the locked files followed by the user who locked each of them and the files’ IDs.
The branch being pushed to is the first parameter to the update hook. If you want to lock the branch myfeature
for pushing, this code (placed in hooks/update
) will do it:
#!/bin/sh # lock the myfeature branch for pushing refname="$1" if [[ $refname == "refs/heads/myfeature" ]] then echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" echo "You cannot push to myfeature! It's locked" echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" exit 1 fi exit 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With