环境:window 10
git version 2.7.2.windows.1
博客案例适用于ssh链接。https链接还不会
重点就是两个部分:
~/.ssh/config 内容:
#user for myself github
Host github_gt
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
./.git/config 内容:
[remote "origin"]
url = git@github_ec/276073970/ecWeb.git
fetch = +refs/heads/*:refs/remotes/origin/*
#截取的部分内容
以下为完整过程:
1.创建ssh 在 git bash
ssh-keygen -t rsa -f /c/User/GT/.ssh/id_rsa_ec -C "username"
#注:
#-t 表示加密类型 rsa
#-f 表示文件路径
#-C 注释,,,登陆时使用的用户名?(后面没有用到)
#id_rsa_ec是私钥文件名
2. ssh-agent ssh-add ~/.ssh/id_rsa_ec
#非默认id-rsa文件需要将ssh添加到ssh-agent
3. 在~/.ssh/下建立config文件,文件内容:
#user for myself github
Host github_gt
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
#user for ecWeb_github
Host github_ec
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_ec
#user for github_aaa
Host github_aaa
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_aaa
#注:可以只有1个,也可以有多个
#Host 表示别名,用于区分和确定当前 链接 的gitHub仓库
#IdentityFile 表示ssh私钥文件,会用它与之比对
# ssh 方式 关联 github库
# ----> 后面 git remote add origin git@github_ec:276073970/ecWeb.git
# 其中的HOST就是用于git@HOST
4. 将公钥添加到gitHub后台
可以测试 ssh链接
eg:
ssh -T git@github_ec
显示结果为:Hi 276073970! You've successfully authenticated, but GitHub does not provide shell access.
其中,276073970 是 github仓库所有者的用户名
5. git init
# 初始化本地仓库
6. git remote add origin git@github_ec:276073970/ecWeb.git
# 关联本地仓库与远程仓库
# 后面可以修改,在 ./.git/config文件
# 修改: url = git@github_ec:276073970/ecWeb.git
7. vim newfile
git add newfile
git commit -m "message" newfile
git push -u origin master #初次
#git push 非第一次
附:
~/.ssh/config文件
#user for myself github
Host github_gt
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
#user for ecWeb_github
Host github_ec
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_ec
#user for github_aaa
Host github_aaa
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_aaa
./.git/config文件
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "origin"]
url = git@github_ec:276073970/ecWeb.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master