- 创建一个ssh key
ssh-keygen -t rsa -C "your_email@youremail.com"
- 后面的your_email@youremail.com改为你在github上注册的邮箱
- 会要求确认路径和输入密码,我们这使用默认的一路回车就行。
- 成功后会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。
- 回到github上,进入 Account Settings(账户配置),左边选择SSH Keys,Add SSH Key,title填写电脑的名字或者其它标题,粘贴在你电脑上生成的key。
- 测试连接是否成功
ssh -T git@github.com
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Hi 15001310187! You've successfully authenticated, but GitHub does not provide shell access.
巴拉巴拉一大堆,看最后的You've successfully authenticated,已经连接上了。
- 上传本地仓库
- 首先在本地搞一个要做仓库的文件夹,然后执行
git init
- 绑定用户名、邮箱。
git config --global user.name 用户名
git config --global user.email 邮箱
git config --list # 查看配置信息
- 查看当前仓库状态
在你已经初始化好的文件夹中,也就是执行过git init的文件夹
git status
git add <file> # . 或 * 代表全部添加
git commit -m "注释文本" #添加注释
- 如果在命令行中文有问题,文件名中文有问题 输入下面
#不对0x80以上的字符进行quote,解决git status/commit时中文文件名乱码
git config --global core.quotepath false
- 空仓库在网页上创建好之后,第一次需要提交一些信息。
git remote add origin git@github.com:你的昵称/仓库名.git
git push -u origin master
第一次提交之后,以后再提交时就可以按照 先ADD,再COMMIT 最后直接PUSH到远程仓库的方式进行了
在.git文件夹中的config文件里存放着提交地址和用户信息
如果在网页上修改,或者远程仓库有变动造成push报错。。
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/Gamestart/My_logging'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
需要先pull一下
git pull --rebase origin master
然后在进行push
git push origin master