Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to lock a branch in GIT

Tags:

git

git-branch

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?

like image 889
Senthil A Kumar Avatar asked Mar 18 '10 16:03

Senthil A Kumar


People also ask

How do I make a branch not Deletable?

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!

How to protect your Git branches and restrict them?

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.

How do I lock a file in Git?

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.

What is a local branch in Git?

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.

How do I create a multi-branch lock in Git?

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.


1 Answers

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 
like image 58
eckes Avatar answered Sep 18 '22 17:09

eckes