Is there a way to lock individual files or directories on fork when using git?

Solution 1:

No chance, if file is not mergeable and you need to lock it, use a centralized solution instead of GIT, i.e. SVN or ClearCase.

Solution 2:

If you are using git LFS (which is supported by some git hosting providers, like GitHub) you could use File Locking.

Mark a file type as lockable by editing the .gitattributes file:

*.docx lockable
# Make MS Word files lockable

And lock it with:

$ git lfs lock example.docx

You can unlock your files with git lfs unlock example.docx and those of somebody else by adding --force.

Solution 3:

this is possible. git-lfs 2.0 introduces the ability to lock files: see these links: https://github.com/git-lfs/git-lfs/wiki/File-Locking. Support for this feature is available starting from TFS 2017.2: https://docs.microsoft.com/en-us/vsts/release-notes/.

Solution 4:

Not exactly locking, but Github has introduced a concept called "Code Owners". Allows you to restrict part of your codebase to only allow commits after review by the code owners

Solution 5:

You can use LFS and you could lock individual files, or instead jus add the files to .gitattributes file,

https://github.com/git-lfs/git-lfs/wiki/File-Locking