Git配置遠程倉庫(密匙鏈接)


Git配置遠程倉庫(密匙鏈接)

主機名 IP 備注
git01 192.168.200.31 git測試客戶端一
git02 192.168.200.32 git測試客戶端二

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

#服務器創建密匙
[root@git01 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:hqeoMxJx57FYYqSsryd3KD6DpAXCMgLXFM8G/LqfACY root@git01
The key's randomart image is:
+---[RSA 2048]----+
|   ++.           |
|. o o+           |
|++   .+          |
|Oo+ +...         |
|E*o* +. S        |
|o+o.+. +         |
|++ .o..          |
|*oB.o. .         |
|oO++ .o          |
+----[SHA256]-----+


#查看密匙
[root@git01 ~]# cat /root/.ssh/id_rsa.pub
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客戶端

[root@git01 ~]# yum -y install git

[root@git01 ~]# git --version
git version 1.8.3.1

3.init初始化GIT工作目錄

[root@git01 ~]# mkdir -p /mycode
[root@git01 ~]# cd /mycode/
[root@git01 mycode]# git init
初始化空的 Git 版本庫於 /mycode/.git/

4.add將變更添加進入暫存區

[root@git01 mycode]# touch test.txt
[root@git01 mycode]# echo "這是一次測試" > test.txt
[root@git01 mycode]# cat test.txt 
這是一次測試

[root@git01 mycode]# git add test.txt
[root@git01 mycode]# git status      #查看git工作目錄的暫存區狀態
# 位於分支 master
#
# 初始提交
#
# 要提交的變更:
#   (使用 "git rm --cached <file>..." 撤出暫存區)
#
#	新文件:    test.txt
#

5.Git全局配置

[root@git01 mycode]# git config --global user.name "Mr.yang"
[root@git01 mycode]# git config --global user.email "1773464408@qq.com"

#說明:如果沒有提前設置Git的全局配置,那么在第一次進行代碼提交的時候,會要求輸入使用者的郵箱和姓名

6.commit將變更從暫存區提交到本地倉庫

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

7.remote add添加一個遠程倉庫的URL

[root@git01 mycode]# git remote add test git@github.com:ywb971108/ceshi.git

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

8.push將本地倉庫的變更推送到遠程倉庫的某個分支

命令格式: git push -u <遠程倉庫的名字> <遠程倉庫的某一分支名字>

[root@git01 mycode]# git push -u test master
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
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.
Counting objects: 3, done.
Writing objects: 100% (3/3), 246 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:ywb971108/ceshi.git
 * [new branch]      master -> master
分支 master 設置為跟蹤來自 test 的遠程分支 master。

9.刷新瀏覽器查看

image_1f0io8948h172ltnfm19l819g83k.png-452.4kB

image_1f0io9rfv12unaif1rja1fss118c41.png-397.7kB

10.clone克隆一個現有倉庫到本地

我們在另一台git02上來模擬其他客戶端進行對遠程倉庫克隆到本地倉庫的操作
git02服務器需要添加密匙到github

[root@git02 ~]# mkdir -p /mycode2
[root@git02 ~]# cd /mycode2/

[root@git02 mycode2]# git clone git@github.com:ywb971108/ceshi.git
正克隆到 'ceshi'...
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
接收對象中: 100% (3/3), done.
[root@git02 mycode2]# ls
ceshi

[root@git02 mycode2]# cd ceshi/
[root@git02 ceshi]# ls
test.txt

[root@git02 ceshi]# cat test.txt 
這是一次測試

11.修改倉庫里的文件內容,並提交變更到本地,推送變更到遠程倉庫

[root@git02 ceshi]# echo "客戶端測試" >> test.txt 
[root@git02 ceshi]# cat test.txt 
這是一次測試
客戶端測試

[root@git02 ceshi]# git add test.txt 
[root@git02 ceshi]# git commit -m "增加了一行內容"
[master 1c90ca0] 增加了一行內容
 1 file changed, 1 insertion(+)

12.客戶端推送到遠程倉庫

#添加對遠程倉庫的管理
[root@git02 ceshi]# git remote add test git@github.com:ywb971108/ceshi.git

#推送到遠程倉庫
[root@git02 ceshi]# git push test master
Counting objects: 5, done.
Writing objects: 100% (3/3), 299 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:ywb971108/ceshi.git
   84a5a58..1c90ca0  master -> master

13.web頁面查看推送結果

image_1f0ipsdhg1di3alp8t31rea1e864e.png-360.7kB

image_1f0ipt4jtert1ihq5tnsi41vhb4r.png-281kB


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM