GitHub初始配置
- 设置git试用的姓名和邮箱地址。
git config --global user.name "dongdong wu"
git config --global user.email "745661590@qq.com"
cat .gitconfig
//会显示
[user]
name = dongdong wu
email = 745661590@qq.com
-
提高代码可读性(暂时没体验到用处)
git config --global color.ui auto cat .gitconfig //会显示 [color] ui = auto
-
创建GitHub用户
-
就可以得到公开界面的URL:https://github.com/Thor-jelly
-
设置一个头像
-
设置SSH Key 官网介绍地址
- 创建SSH Key
ssh-keygen -t rsa -C "745661590@qq.com" Generating public/private rsa key pair. //输入文件名称,可以直接回车键 Enter file in which to save the key (/Users/shandian/.ssh/id_rsa): Created directory '/Users/shandian/.ssh'. //输入密码 Enter passphrase (empty for no passphrase): //再次输入密码 Enter same passphrase again: Your identification has been saved in /Users/shandian/.ssh/id_rsa. Your public key has been saved in /Users/shandian/.ssh/id_rsa.pub. The key fingerprint is: //会得到--fingerprint值 和 你输的邮箱 fingerprint值 745661590@qq.com The key's randomart image is: +---[RSA 2048]----+ | | | |
这样就会创建了SSH Key,其中id_rsa是私有秘钥,id_rsa.pub是公开秘钥
查看公共秘钥中的内容cat ~/.ssh/id_rsa.pub //会得到 公开秘钥内容 745661590@qq.com
- 添加公开秘钥
-
点击 new ssh key 按钮进行添加key,设置key 名称和key。
image
如果添加成功了,你就会收到一份邮件:公共秘钥添加成功
-
完成上述设置后,就可以用私人秘钥与GitHub进行认证和通信了。
ssh -T git@github.com The authenticity of host 'github.com (192.30.255.112)' can't be established. RSA key fingerprint is `fingerprint值` Are you sure you want to continue connecting (yes/no)? //输入yes Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts. Enter passphrase for key '/Users/shandian/.ssh/id_rsa': //输入密码 //出现下面提示表明成功 Hi Thor-jelly! You've successfully authenticated, but GitHub does not provide shell access.
-
仓库
-
创建--》点击工具栏-new repository
image
全部填写好,点击create repository -
复制项目URL:git@github.com:Thor-jelly/Test.git
在git中clone项目有两种方式:HTTPS和SSH,它们的区别如下:
- HTTPS:不管是谁,拿到url随便clone,但是在push的时候需要验证用户名和密码;
- SSH:clone的项目你必须是拥有者或者管理员,而且需要在clone前添加SSH Key。
- SSH 在push的时候,是不需要输入用户名的,如果配置SSH key的时候设置了密码,则需要输入密码的,否则直接是不需要输入密码的。
-
clone项目
git clone git@github.com:Thor-jelly/Test.git Cloning into 'Test'... remote: Counting objects: 4, done. remote: Compressing objects: 100% (3/3), done. remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (4/4), done.
-
更改README文件内容
# Test 测试使用GitHub ## 我的第一次提交到GitHub
-
提交代码
- 先查看当前状态
git status
- 提交
git add 当前文件名 //把文件添加到暂存区 git commit -m "first commit" //再通过改命令进行提交
- 查看提交日志
git log
- 提交到仓库
git push
- 先查看当前状态
网友评论