linux git关联远程,使用Git连接本地和远程GitHub

网上很多github的流程比较乱,自己尝试整理了一下,主要是步骤较为清晰,如果有不清楚的可详细进行搜索对比

1. 申请和设置github

https://github.com/

该过程请自行参考

2. 使用gitbash设置用户名和邮箱

打开gitbash,输入命令设置用户名和邮箱

$ git config --global user.name "your name"

$ git config --global user.email "your email"

3. 生成ssh配置

通过邮箱名称生成ssh key,在输入第一行命令后火提示输入保存key的地址,根据自己的结构指定文件的地址,

$ ssh-keygen -t rsa -C "xxx@gmail.com"

Generating public/private rsa key pair.

Enter file in which to save the key (/c/Users/kf/.ssh/id_rsa): D:/ssh/github

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in D:/ssh/github.

Your public key has been saved in D:/ssh/github.pub.

The key fingerprint is:

SHA256:8J70WllHBwvnolh+LVG2pIOMKRkhzJibLjyoiZNBXvA

xxx@gmail.com

The key's randomart image is:

+---[RSA 2048]----+

|  =. o.    . *  |

| .o o. o + . O + |

|  oo  + o + = = .|

| .oE  + + . * . |

|=..    S o + o  |

|++.    o o + o  |

|o=.    o +      |

|*        o      |

| .      .        |

+----[SHA256]-----+

4. 配置github ssh

执行成功后,生成目录下会生成两个文件,一个是私钥一个是公钥,找到后缀是 .pub 的公钥文件,拷贝全部文件内容到github中,具体方法是在github页面中Settings > SSH and GPG keys > New SSH key 中设置,title内容随意设置。

5. 配置本地ssh

执行ssh-add -l 查看本地ssh配置情况

$ ssh-add -l

如果返回如下,则说明配置正确

2048 SHA256:8J70WllHBwvnolh+LVG2pIOMKRkhzJibLjyoiZNBXvA /d/ssh/github (RSA)

如果返回下面一句话,这说明没有起效

Could not open a connection to your authentication agent.

需要执行如下语句:

$ ssh-agent bash

$ ssh-add /d/ssh/github

6. 验证连接

ssh配置成功后验证是否能够正确连接github

$ ssh -T git@github.com

Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

7. 与github同步

将本地项目上传到github

$ git remote add origin git@github.com:your_project.git

$ git push -u origin master

如果本地没有则先下载到本地再同步

$ git clone your_project.git

$ git push -u origin master

0b1331709591d260c1c78e86d0c51c18.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值