# 查看全局的username(git commit的用户名)和email配置
git config --global --list
# ssh配置目录
cd ~/.ssh
# 生成ssh key 确定
ssh-keygen -t rsa -C " your email"
# 填写自定义文件名
Enter file in which to save the key (~/.ssh/id_rsa): "……"
# 编辑~/.ssh/config文件
# HostName 真实的服务地址
# Host 别名
# IdentityFile 证书所在位置
Host dc_1
HostName codehub.devcloud.*cloud.com
IdentityFile ~/.ssh/dc_1
PreferredAuthentications publickey
User username1
Host dc_2
HostName codehub.devcloud.*cloud.com
IdentityFile ~/.ssh/dc_2
PreferredAuthentications publickey
User username2
# 在github上配置ssh_key 自己生成的id_rsa.pub文件的内容
# 测试
ssh -T git@Host
# 进入项目目录,本地配置
git config --local user.name "你的名字"
git config --local user.email "你的邮箱"
# 项目下
git init
# 绑定github上面的项目
git remote add "git@github.com/……"
# 遇到的问题 git push的时候 报错 permission denied(publickey) 但是ssh -T正常
https://blog.csdn.net/fredricen/article/details/106550799?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242
git使用命令
# 查看已commit到repository的文件
git ls-files
# 查看未提交到repository的文件
git status
# 查看本地分支,带*为当前所在分支
git branch
# 提交
git commit -m "commit注释"
# 拉取远程
git pull origin master
# 推送代码
git push -u origin master
参考资料:
1.https://zhuanlan.zhihu.com/p/23167699
2.知乎搜索:电脑上配置两个git账号
3.http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html