管理 GitHub 权限每个目录的术语是什么?

huangapple go评论74阅读模式
英文:

What is the term for managing GitHub permissions per directory?

问题

不确定我是否正确提出了问题。

我有一个用于company1.com/foo的存储库,位于目录~/go/foo中,用于公司foo。我有一个用于company2.com/bar的存储库,位于目录~/go/bar中。我希望当我在本地存储库中工作时,git可以查看.git目录以获取完全不同的权限设置,甚至不同的用户。

当我在foo存储库上工作时,我希望它期望company1.com的凭据,因此git push从~/go/foo更新https://github.com/company1/foo,使用用户IDfred@company.com。当我在~/go/bar上工作bar存储库时,执行git push时,它使用用户IDfredz@company2.com的凭据,并更新https://github.com/company2/bar。

我正在尝试在git-scm.org上查找这个问题,但我不知道艺术的术语。类似于“每个存储库的GitHub权限”或“本地git权限”之类的东西?

英文:

Not even sure if I asked the question right.

I have a repo for company1.com/foo which lives in directory ~/go/foo, for company foo. I have a repo for company2.com/bar which lives in directory ~/go/bar. I am hoping that when I'm working in the local repos git can look in the .git directory for completely different sets of permissions and even users.

When I'm working on the foo repo I'd like it to expect credentials for company1.com, so git push from ~/go/foo updates https://github.com/company1/foo with user ID fred@company.com. When I'm working on the bar repo from ~/go/bar, and do a git push it uses credentials for user ID fredz@company2.com and updates https://github.com/company2/bar.

I'm trying to look this up on git-scm.org but I don't know the term of art. Something like "per repo GitHub permissions" or "local git permissions" or something?

答案1

得分: 2

最简单的解决方案是在全局 Git 配置中将 credential.useHttpPath 设置为 True:

git config --global credential.useHttpPath true

根据git凭据手册的说明:

> useHttpPath
默认情况下,Git 不会考虑 http URL 的“path”组件是否值得通过外部辅助程序进行匹配。这意味着为 https://example.com/foo.git 存储的凭据也将用于 https://example.com/bar.git。如果您确实想区分这些情况,请将此选项设置为 true。

英文:

The simplest solution is to set credential.useHttpPath to True in your global Git configuration:

git config --global credential.useHttpPath true

According to the manual for git credentials:

> useHttpPath
By default, Git does not consider the "path" component of an http URL to be worth matching via external helpers. This means that a credential stored for https://example.com/foo.git will also be used for https://example.com/bar.git. If you do want to distinguish these cases, set this option to true.

答案2

得分: 0

git config 可以在多个级别指定。根据文档

在写入时,默认情况下将新值写入存储库的本地配置文件,并且可以使用选项--system、--global、--worktree、--file 来告诉命令写入该位置(您可以说--local,但那是默认值)。

所以似乎 git config user.name "My Name"git config user.email "my@email.com" 只要您在正确的目录中运行它们,就会实现您想要的效果。

英文:

git config can be specified at several levels. From the docs:

> When writing, the new value is written to the repository local configuration file by default, and options --system, --global, --worktree, --file <filename> can be used to tell the command to write to that location (you can say --local but that is the default).

So it seems like git config user.name &quot;My Name&quot; and git config user.email &quot;my@email.com&quot; will do what you want as long as you run them in the correct directories.

huangapple
  • 本文由 发表于 2023年6月1日 05:44:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76377496.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定