Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you explain why you would lock a remote branch in Git?

I was holding an introductory presentation on GIT when someone from the audience asked me how to lock a remote branch, preventing a push from someone else.

I understand why a person that has been using TFS wonders about it, but are there reasons why you would need to lock a remote repository in GIT? If so, which ones?

like image 563
MaPi Avatar asked Oct 21 '22 02:10

MaPi


1 Answers

Locking a branch in TFS makes it read only (see "Making a TFS Branch Read-Only")

Git itself isn't able to make a branch read-only: if you have access to a git repo, you clone it all (with all its branch), and you can commit in any branch.

You can control what is pushed through:

  • server-side hook, like an update hooks (called for each branch pushed, see example)
  • an authorization layer like gitolite, which can protect a branch with access rules.

That means you can put in place a policy (hook or gitolite) which will prevent the modified branch to be pushed to the upstream repo.

like image 95
VonC Avatar answered Oct 22 '22 23:10

VonC