How do I lock files in a Git repository to prevent others from working on the same file?

Tezino, Angelique 21 Reputation points
2021-10-19T15:37:46.01+00:00

Hello,

I'm very new to Azure DevOps, and I've used TFS for version control in the past for our .rdl files. Now we are using Git in Azure DevOps for source control. I have a repository with several files that will be used by more than one developer. We work on files that are assigned to us, but every now and then one Developer might work on a file that belongs to another Developer. I know TFS will lock files to prevent overlap, but how do we lock files using Git to prevent another developer from working on the same file? Any help is much appreciated.

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,793 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 47,716 Reputation points
    2021-10-19T15:54:59.063+00:00

    You can't. That is exactly what Git is all about. It is designed to allow multiple people to be working on any # of files at the same time. There is no "lock" concept. When a user attempts to push a change to a file that was changed after they had pulled it then they get a merge conflict and have to merge their changes with the changes on the server. This is a far better approach than the old TFVC system in which a user might check out a file and leave it checked out even if they never touch it and/or the changes they make aren't conflicting with changes made by someone else in the same file.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Joyzhao-MSFT 15,566 Reputation points
    2021-10-20T03:35:04.827+00:00

    Hi @Tezino, Angelique ,
    Unfortunately you cannot use Git to lock files to prevent other developers from working on the same file.
    If you are using git LFS (which is supported by some git hosting providers, like GitHub、GitLab) you could use File Locking.
    Best Regards,
    Joy


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.