当前位置:   article > 正文

Git配置远程仓库(密匙链接)

remote: total 3 (delta 0), reused 0 (delta 0), pack-reused 3 unpacking objec

Git配置远程仓库(密匙链接)

主机名IP备注
git01192.168.200.31git测试客户端一
git02192.168.200.32git测试客户端二

1.建立远程仓库

首先在浏览器中输入网址https://github.com

image_1f0iicie11ed61591ja087kf479.png-660.4kB

image_1f0iio1djm5qa354efj0e1janm.png-435.4kB

image_1f0ik0rje10nda9t12hr14li1mk313.png-497.9kB

image_1f0ikcv9fntpf20vel19k616l01g.png-132.6kB

image_1f0ikg2kv17ni191g1m2p1fumsv62d.png-417.2kB

  1. #服务器创建密匙
  2. [root@git01 ~]# ssh-keygen
  3. Generating public/private rsa key pair.
  4. Enter file in which to save the key (/root/.ssh/id_rsa):
  5. Created directory '/root/.ssh'.
  6. Enter passphrase (empty for no passphrase):
  7. Enter same passphrase again:
  8. Your identification has been saved in /root/.ssh/id_rsa.
  9. Your public key has been saved in /root/.ssh/id_rsa.pub.
  10. The key fingerprint is:
  11. SHA256:hqeoMxJx57FYYqSsryd3KD6DpAXCMgLXFM8G/LqfACY root@git01
  12. The key's randomart image is:
  13. +---[RSA 2048]----+
  14. | ++. |
  15. |. o o+ |
  16. |++ .+ |
  17. |Oo+ +... |
  18. |E*o* +. S |
  19. |o+o.+. + |
  20. |++ .o.. |
  21. |*oB.o. . |
  22. |oO++ .o |
  23. +----[SHA256]-----+
  24. #查看密匙
  25. [root@git01 ~]# cat /root/.ssh/id_rsa.pub
  26. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCfJK+sdi8thBg+0VpbuBYyJIm5u4Mzrrk9jmu36/m9gEJiIsVkzWR4F51uuNwYwqEWuCl4f7BY/rDGe/eRlv4c2Qn0C0APNjNqRNXQXEfm7HFnWrjc75TybX3OkM6CEskKwAqB7YTNwFSt0DTic8sOuQKp+Y1o32n9tr/gjUCPZkx3+NLbXODws/Lroew0p21XVNH4Fd8H/k6/uciLm5vpXmBhy5a49uikkn0Jyx/wRUNZfRAhkmRKBTVgzdrcZ8W0yQjyFP7DjiCwnBXzP9NKyAhOVXlpEnfpGfqUBFZPl8c/SzHPDNbedbdM9CTbly0cm0yDgrO+TUjD6b7a87E7 root@git01

image_1f0ikm2v6vak1l831ghhm0m4n12q.png-558.8kB

image_1f0ikr9ca1n4c157q170o4dq196t37.png-515.4kB

2.yum安装git客户端

  1. [root@git01 ~]# yum -y install git
  2. [root@git01 ~]# git --version
  3. git version 1.8.3.1

3.init初始化GIT工作目录

  1. [root@git01 ~]# mkdir -p /mycode
  2. [root@git01 ~]# cd /mycode/
  3. [root@git01 mycode]# git init
  4. 初始化空的 Git 版本库于 /mycode/.git/

4.add将变更添加进入暂存区

  1. [root@git01 mycode]# touch test.txt
  2. [root@git01 mycode]# echo "这是一次测试" > test.txt
  3. [root@git01 mycode]# cat test.txt
  4. 这是一次测试
  5. [root@git01 mycode]# git add test.txt
  6. [root@git01 mycode]# git status #查看git工作目录的暂存区状态
  7. # 位于分支 master
  8. #
  9. # 初始提交
  10. #
  11. # 要提交的变更:
  12. # (使用 "git rm --cached <file>..." 撤出暂存区)
  13. #
  14. # 新文件: test.txt
  15. #

5.Git全局配置

  1. [root@git01 mycode]# git config --global user.name "Mr.yang"
  2. [root@git01 mycode]# git config --global user.email "1773464408@qq.com"
  3. #说明:如果没有提前设置Git的全局配置,那么在第一次进行代码提交的时候,会要求输入使用者的邮箱和姓名

6.commit将变更从暂存区提交到本地仓库

  1. [root@git01 mycode]# git commit -m "第一次测试"
  2. [master(根提交) 84a5a58] 第一次测试
  3. 1 file changed, 1 insertion(+)
  4. create mode 100644 test.txt

7.remote add添加一个远程仓库的URL

  1. [root@git01 mycode]# git remote add test git@github.com:ywb971108/ceshi.git
  2. [root@git01 mycode]# git remote -v
  3. test git@github.com:ywb971108/ceshi.git (fetch)
  4. test git@github.com:ywb971108/ceshi.git (push)

8.push将本地仓库的变更推送到远程仓库的某个分支

命令格式: git push -u <远程仓库的名字> <远程仓库的某一分支名字>

  1. [root@git01 mycode]# git push -u test master
  2. The authenticity of host 'github.com (13.250.177.223)' can't be established.
  3. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
  4. RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
  5. Are you sure you want to continue connecting (yes/no)? yes
  6. Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
  7. Counting objects: 3, done.
  8. Writing objects: 100% (3/3), 246 bytes | 0 bytes/s, done.
  9. Total 3 (delta 0), reused 0 (delta 0)
  10. To git@github.com:ywb971108/ceshi.git
  11. * [new branch] master -> master
  12. 分支 master 设置为跟踪来自 test 的远程分支 master。

9.刷新浏览器查看

image_1f0io8948h172ltnfm19l819g83k.png-452.4kB

image_1f0io9rfv12unaif1rja1fss118c41.png-397.7kB

10.clone克隆一个现有仓库到本地

我们在另一台git02上来模拟其他客户端进行对远程仓库克隆到本地仓库的操作
git02服务器需要添加密匙到github

  1. [root@git02 ~]# mkdir -p /mycode2
  2. [root@git02 ~]# cd /mycode2/
  3. [root@git02 mycode2]# git clone git@github.com:ywb971108/ceshi.git
  4. 正克隆到 'ceshi'...
  5. Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
  6. remote: Enumerating objects: 3, done.
  7. remote: Counting objects: 100% (3/3), done.
  8. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
  9. 接收对象中: 100% (3/3), done.
  1. [root@git02 mycode2]# ls
  2. ceshi
  3. [root@git02 mycode2]# cd ceshi/
  4. [root@git02 ceshi]# ls
  5. test.txt
  6. [root@git02 ceshi]# cat test.txt
  7. 这是一次测试

11.修改仓库里的文件内容,并提交变更到本地,推送变更到远程仓库

  1. [root@git02 ceshi]# echo "客户端测试" >> test.txt
  2. [root@git02 ceshi]# cat test.txt
  3. 这是一次测试
  4. 客户端测试
  5. [root@git02 ceshi]# git add test.txt
  6. [root@git02 ceshi]# git commit -m "增加了一行内容"
  7. [master 1c90ca0] 增加了一行内容
  8. 1 file changed, 1 insertion(+)

12.客户端推送到远程仓库

  1. #添加对远程仓库的管理
  2. [root@git02 ceshi]# git remote add test git@github.com:ywb971108/ceshi.git
  3. #推送到远程仓库
  4. [root@git02 ceshi]# git push test master
  5. Counting objects: 5, done.
  6. Writing objects: 100% (3/3), 299 bytes | 0 bytes/s, done.
  7. Total 3 (delta 0), reused 0 (delta 0)
  8. To git@github.com:ywb971108/ceshi.git
  9. 84a5a58..1c90ca0 master -> master

13.web页面查看推送结果

image_1f0ipsdhg1di3alp8t31rea1e864e.png-360.7kB

image_1f0ipt4jtert1ihq5tnsi41vhb4r.png-281kB

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/699658
推荐阅读
相关标签
  

闽ICP备14008679号