git:include如果不使用git clone [英] git: includeIf not working with git clone

查看:135
本文介绍了git:include如果不使用git clone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.gitconfig :

[user]
    name = Dr.jacky
    email = personal.email@gmail.com
    signingKey = ""
[includeIf "gitdir:/Users/drjacky/Projects/CompanyName/"]
    path = /Users/drjacky/gitconfigcompanyname/.gitconfig
[core]
    excludesfile = /Users/drjacky/.gitignore_global
    autocrlf = input
[difftool "sourcetree"]
    cmd = opendiff \"$LOCAL\" \"$REMOTE\"
    path = 
[mergetool "sourcetree"]
    cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
    trustExitCode = true
[commit]
    template = /Users/drjacky/.stCommitMsg
    gpgSign = false
[gpg]
    program = gpg
[tag]
    forceSignAnnotated = false

gitconfigcompanyname/.gitconfig :

[user]
    name = My Name
    email = my.company.email@company.com

.ssh/config :


# --- Sourcetree Generated ---
Host Personal-GitHub
    HostName github.com
    User Drjacky
    PreferredAuthentications publickey
# IdentityFile /Users/drjacky/.ssh/Personal-GitHub
    IdentityFile ~/.ssh/id_rsa
    UseKeychain yes
    AddKeysToAgent yes
# ----------------------------
# Company Work GitHub
Host github.com/Company
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_companyname
    UseKeychain yes
    AddKeysToAgent yes

我通过ssh-add添加了第二个ssh pub.

I've added the second ssh pub via ssh-add.

现在,在终端/iTerm2上,我重定向到/Users/drjacky/Projects/CompanyName/HERE,然后运行以下命令: git clone httpUrlOfMyCompanyRepogit clone sshOfMyCompanyRepo;没关系,它没有访问权限:

Now, on the terminal/iTerm2, I redirect to /Users/drjacky/Projects/CompanyName/HERE, then run this: git clone httpUrlOfMyCompanyRepo or git clone sshOfMyCompanyRepo; Doesn't matter, it doesn't have access:

远程:未找到存储库. 致命:找不到存储库"https://github.com/CompanyName/reponame.git/"

remote: Repository not found. fatal: repository 'https://github.com/CompanyName/reponame.git/' not found

当我运行git config user.email时,在CompanyName文件夹路径下,它显示了我的个人电子邮件.

And when I run git config user.email, under CompanyName folder path, it shows my personal email.

当我运行git config --list时:

credential.helper=osxkeychain
user.name=Dr.jacky
user.email=personal.email@gmail.com
user.signingkey=
includeif.gitdir:/Users/drjacky/Projectz/CompanyName/.path=/Users/drjacky/gitconfigcompanyname/.gitconfig
core.excludesfile=/Users/drjacky/.gitignore_global
core.autocrlf=input
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=/Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
commit.template=/Users/drjacky/.stCommitMsg
commit.gpgsign=false
gpg.program=gpg
tag.forcesignannotated=false
(END)

git bugreport:

[System Info]
git version:
git version 2.28.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Darwin 19.6.0 Darwin Kernel Version 19.6.0: Sun Jul  5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64 x86_64
compiler info: clang: 11.0.3 (clang-1103.0.32.62)
libc info: no libc information available
$SHELL (typically, interactive shell): /bin/zsh

注释:

  • 我已经卸载了SourceTree,但没有帮助.
  • git版本2.28.0
  • 使用工具成功克隆存储库后,它可以正确使用而不会出现问题.

更新: 我已经检查了Github仪表板上的SSH部分,它显示SSH密钥根本没有使用!

Update: I've check SSH section on Github dashboard, and it shows the SSH key has not been used at all!

推荐答案

我必须将ssh/config中的Host github.com/Company更改为Host github.com-Company. 然后,像这样克隆: git clone git@github.com-Company:Company/repoName.git

I had to change Host github.com/Company to Host github.com-Company in ssh/config. Then, clone like this: git clone git@github.com-Company:Company/repoName.git

但是,仍然希望有一个更好的解决方案,而不是更改ssh地址/HTTP URL.

来源:

  • https://gist.github.com/jexchan/2351996
  • https://gist.github.com/jexchan/2351996#gistcomment-826728

更新:

根据此评论:
用于个人/其他所有项目的个人.gitconfig:

According to this comment:
Personal .gitconfig for personal/everything else projects:

[user]
    name = Dr.jacky
    email = email@personal.com
[core]
        sshCommand = ssh -i ~/.ssh/id_rsa -F /dev/null

公司项目的工作.gitconfig:

[user]
    name = Work Name
    email = work@company.com
[core]
        sshCommand = ssh -i ~/.ssh/id_rsa_companyname -F /dev/null

并将全局.gitconfig更改为此:

[user]
    name = Dr.jacky
    email = email@personal.com
    signingKey = ""
[includeIf "gitdir:/Users/drjacky/*"]
    path = /Users/drjacky/gitconfigpersonal/.gitconfig
[includeIf "gitdir:/Users/drjacky/Projectz/CompanyName/"]
    path = /Users/drjacky/gitconfigcompanyname/.gitconfig

感谢 leddzip

这篇关于git:include如果不使用git clone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆