github使用

1、GitHub注册

        官网:(科学上网)GitHub: Let’s build from here · GitHubGitHub is where over 100 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and features, power your CI/CD and DevOps workflows, and secure code before you commit it.icon-default.png?t=O83Ahttps://github.com/        在官网上注册账号并登录

2、git客户端

        1、github.com 注册账户

        2、在github上创建仓库

 

 

 此时还不能跟远程仓库建立连接,因为没有密钥!!!

1.生成本地ssh key

[root@localhost ~]# 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:FrN6flXCRifmyoFXEKvHDV2ET5nZxTC7zliqJkAcDpw root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|   . .    oo o=Bo|
|    E .    o*.*oo|
|     + .o.o*.=.  |
|      + .*oo= o. |
|     .  Soo+.oo  |
|      .o .o .*   |
|      ...  .o o  |
|       o. o.     |
|        .+.      |
+----[SHA256]-----+

2.复制 公钥,在github 中添加ssh key  

[root@localhost ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAFUYg6/Mput
5Dta9zLo5YVS1AcVyipLJU9Z1gRfWjOVZFNpBmM10JviRUj2gb
2MZdYNlyOVUxxT5CYaDvidARWwX+ohJJuilFgZuDEq2vI3BXQ+
/YHwuktDNIZT5bEsUvDF1hWaT7yVlvpIRbZ3UkF0S8cBpBFZwz
n9F9VUsXa+rgm7EhexalmT9baDJyHWdICAXQrp5RnSK6vj3xZm
31B1t1hx2Y7sycYo3d2xYXHYTvtirQ6vNDCJL2D4q0mVOL671S
K+XwRUqrNyscdLkh3a9ysxZT04IYyaR3ZgSVI0ua52Tae/s+ax
w//pF4sMfpf7zopxPxSL7/GdFGY7rr root@localhost.localdomain

        在github找到账户设置

 

 选择ssh key

 

 3.测试本地客户端,进行认证(但不能远程连接)

# yum install git
[root@localhost ~]# ssh -T git@github.com
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
ECDSA key fingerprint is MD5:7b:99:81:1e:4c:91:a5:0d:5a:2e:2e:80:13:3f:24:ca.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
Hi guohaolu123! You've successfully authenticated, but GitHub does not provide shell access.

4.克隆远程仓库(或者自己创建一个远程同名仓库)

 

[root@localhost ~]# git config --list
[root@localhost ~]# git clone git@github.com:guohaolu123/test_github.git
正克隆到 'test_github'...
warning: 远程 HEAD 指向一个不存在的引用,无法检出。

[root@localhost ~]# ls
anaconda-ks.cfg  a.sh  a.txt  b.sh  dump.rdb  jt.sh  new.txt  
nodes.conf  old,txt  read.sh  test_github(这个文件夹就是远程仓库)

 5.在本地添加远程仓库用户名,在本地添加远程仓库邮箱

[root@localhost test_github]# git config --global user.name 'xiaolu'
[root@localhost test_github]# git config --global user.email '自己邮箱'
[root@localhost test_github]# git config --list 
user.name=xiaolu
user.email=自己邮箱
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:guohaolu123/test_github.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

 6.上传远程仓库

初始化本地仓库:git init

添加文件到暂存区:git add .

提交暂存区的变动到本地仓库:git commit -m 'git本地第一次提交1.sh'

设置远程仓库地址:git remote add origin git@github.com:guohaolu123/test_github.git

将本地仓库的改动推送到远程仓库:git push -u  origin  master

拉:git pull -u origin master(拉之前先初始化一下本地仓库)

[root@localhost test_github]# git init
重新初始化现存的 Git 版本库于 /root/test_github/.git/
[root@localhost test_github]# echo 11111 > 1.sh
[root@localhost test_github]# git add .
[root@localhost test_github]# git commit -m '第一次提交'
[master(根提交) e68c974] 第一次提交
 1 file changed, 1 insertion(+)
 create mode 100644 1.sh
[root@localhost test_github]# git branch -M main
[root@localhost test_github]# git remote add origin git@github.com:guohaolu123/test_github.git

fatal: 远程 origin 已经存在。

[root@localhost test_github]# git push -u origin main
Counting objects: 3, done.
Writing objects: 100% (3/3), 225 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: To git@github.com:guohaolu123/test_github.git
 * [new branch]      main -> main
分支 main 设置为跟踪来自 origin 的远程分支 main。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值