Lock and unlock folders or files in Team Foundation Version Control

TFS 2018

Visual Studio 2019 | Visual Studio 2022

You can use Visual Studio Source Control Explorer to lock or unlock a folder or file tracked by Team Foundation Version Control (TFVC). Lock or unlock files or folders to deny or restore a user's privileges such as checking out an item for edit into a different workspace or checking in pending changes to an item from a different workspace. For more information, see Create and work with workspaces.

Note

This article applies to locking or unlocking files managed by TFVC. For help unlocking files that show in use by programs on your PC, use the Handle and Process Explorer tools to help you find which program is locking your files.

You can use a lock to temporarily freeze the server version of an item so that you can check in a pending change without having to resolve any merge conflicts. If you want to permanently prevent access to an item on the server, you should use the Permission command instead.

Tip

You can use the Lock command to remove another user's lock if you have sufficient permissions.

Prerequisites

See Default TFVC permissions.

Lock a folder or file

Important

The lock type options appear only when you're making changes in a server workspace. The use of local workspaces in your project makes check-out locks un-enforceable. For more information, see Understand lock types.

  1. To open Source Control Explorer in Visual Studio, select View > Other Windows > Source Control Explorer.

    You can also select Source Control Explorer from the Team Explorer window.

  2. In Source Control Explorer, right-click the file you want to lock, and select Advanced > Lock.

  3. In the Lock dialog box, make sure the file or folder you want to lock is selected, select either the Check Out or Check In lock type, and then select Lock. For more information, see Understand lock types.

Source Control Explorer displays the status lock next to the file under Pending Change. The next time your pending changes are checked into the workspace, the lock is removed. For more information, see Check in your work to the team's codebase.

Note

You can also lock folders and files from the command line. For more information, see Lock command.

Unlock a folder or file

Important

You can unlock files other members of your team have locked only if you have UnlockOther permissions. If you don't have permission to unlock a file, the option is inaccessible.

  1. While working in a server workspace in Visual Studio, select View > Other Windows > Source Control Explorer, or select Source Control Explorer from the Team Explorer window.

  2. In Source Control Explorer, right-click the folder or file from which you want to remove a lock, and select Advanced > Unlock.