Git command returns fatal error about the repository being owned by someone else
https://confluence.atlassian.com/bbkb/git-command-returns-fatal-error-about-the-repository-being-owned-by-someone-else-1167744132.html Summary When trying to execute a git command in a repository, suc
目录7 个章节
Summary
When trying to execute a git command in a repository, such as a clone or push, git returns a fatal error saying the repository has dubious ownership and the git command is aborted.
Diagnosis
After executing a git command, an error similar to below is returned :
fatal: detected dubious ownership in repository at '<path to the repository>'
To add an exception for this directory, call:
git config --global --add safe.directory <path to the repository>
or
fatal: unsafe repository ('<path to the repository>' is owned by someone else)
To add an exception for this directory, call:
git config --global --add safe.directory <path to the repository>
Cause
A change was introduced in git 2.35.2 (and newer) to prevent a user from executing git commands in a repository owned by a different user. This is to address a security risk, CVE-2022-24765, for more details see setup_git_directory and Git security vulnerability announced. The change to setup_git_directory prevents git invocations from executing commands on a repository owned by another user.
Solution
On a single user system
Change the owner of the repository folder to the user which is running the git command.
For Windows : One way to do this is with the takeown command:
takeown /f <path to the repository> /r /d y
For Linux: Using the chown command :
chown -R username:group <path to the repository>
Single repository on a multi user system:
The default solution to workaround this issue would be to add the directory in question to git's safe.directory list, as the following command :
git config --global --add safe.directory <path to repository>
This is usually the command suggested by git in the error message to add this directory to the exception list.
Multiple repositories, system global settings:
Add the folder to the safe.directory list at the system level
git config --system --add safe.directory <path to the repository>
If using git > 2.36, there's also a wildcard to add all folders to safe.directory list :
git config --global --add safe.directory '*' # For the current user and all repositories
git config --system --add safe.directory '*' # For all users and all repositories
Before adding paths/repositories to the exception list, please make sure to understand the security implications of CVE-2022-24765 and setup_git_directory. To avoid this, it's strongly recommended for each user have their own clone of the repository.
_EOF_
Git command returns fatal error about the repository being owned by someone else
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
模型文件硬塞进 Git,GitHub 直接打回原形:使用Git-LFS管理大文件
GitHub硬怼大文件?Git LFS了解一下,免费额度逼得你快用完就买。别指望这玩意儿当网盘用,模型放代码里提交是吧?这操作真是下饭。
2025-08-27 · Git · 约 1 分钟
从Git-repository中移除文件
使用 git rm --cached -r 命令,从版本库中移除 git rm -r --cached *.iml output rm 'commons/commons.iml' rm 'estate-repo.iml' rm 'service/service.iml' 然后重新提交
2023-03-20 · Git · 约 1 分钟
导出Git提交记录
https://git-scm.com/docs/git-log#Documentation/git-log.txt-emnem git log export command git log --after=2021-1-1 --before=2022-1-1 --pretty=format:'%cs,%an,%s' output 2021-12-17,DealiAxy,swagger文档优化 2
2023-03-20 · Git · 约 1 分钟
如何清理误提交到git的历史大文件?
作者在更新其视频剪辑工具Clipify时,遇到了Git仓库中大量静态资源文件导致push速度变慢的问题。通过分析,发现使用`git rm --cached`命令无法彻底解决问题,因为Git仍保留历史提交中的大文件。作者最终采用git-filter-repo工具重写Git提交历史,成功解决了push速度慢的问题,并介绍了如何使用git-sizer工具分析Git仓库中的大文件。
2025-09-12 · Git · 约 1 分钟
讨论
共 0 条加载评论中…