Github 使用ssh连接GitHub

网友投稿 563 2022-11-23

Github 使用ssh连接GitHub

Github   使用ssh连接GitHub

​​使用ssh连接GitHub​​

检查电脑是否有SSH密钥

1、打开Git Bash

2、输入ls -al ~/.ssh以查看是否存在现有的SSH密钥

$ ls -al ~/.ssh# Lists the files in your .ssh directory, if they exist

3、检查目录列表,以查看是否已经有公共SSH密钥。默认情况下,公共密钥的文件名是以下之一

id_rsa.pubid_ecdsa.pubid_ed25519.pub

生成SSH密钥

打开Git Bash。

粘贴以下文本,替换为您的GitHub电子邮件地址。

$ ssh-keygen -t ed25519 -C "your_email@example.com"

当提示您“输入要在其中保存密钥的文件”时,请按Enter。接受默认文件位置。

在提示符下,键入一个安全的密码短语

Enter passphrase (empty for no passphrase):

向GitHub帐户添加新的SSH密钥

在将新的SSH密钥添加到GitHub帐户之前要先检查是否有密钥

$ ls -al ~/.ssh

1将SSH公钥复制到剪贴板

$ clip < ~/.ssh/id_ed25519.pub

可使用如下命令验证上述配置是否成功

ssh -T git@github.com

若出现 Are you sure you want to continue connecting (yes/no)? 选择 yes。 出现 You've successfully authenticated, but GitHub does not provide shell access. 说明配置成功。

在本地建立新仓库并将其关联到远程仓库

在本地新建仓库

mkdir warehouse #建立新的本地仓库 cd warehouse git init -- 初始化 git add filename # (or git add *.*) git commit -m "first commit"

将本地仓库与远程仓库关联起来

git init -- 初始化git remote add origin 远程仓库地址.git -- 连接远程仓库git clone git@github.com:.git -- 克隆仓库git remote -v -- 查看是否关联成功

克隆和拉取远程仓库的文件

git clone git@github.com:.git -- 克隆仓库git pull

加入团队远程仓库

首先团队仓库是存在的,并且已经收到团队仓库的加入邀请或许可。 团队仓库一般是 private,先把团队仓库的代码拷贝到本地

git clone htttps://username:password@github.com/team_name/team_repository_name

抓取所需分支

git fetch origin remote_branch_name:local_branch_name

转到所需分支

git checkout local_branch_name

git其他常用操作

(1) 建立新的分支

git checkout -b new_branch

(2) 添加文件并备注信息

git commit -a -m "commit information"// 添加所有文件git commit filename -m "commit information"// 添加某个文件

(3) 向远程添加分支

git push origin local_branch_name:remote_branch_name

(4) 删除本地分支

git branch -D branch_name

(5) 修改本地分支名称

git branch -m old_branch_name new_branch_name

(6) 本地回退到之前的分支

git log

记录 commit 后面的分支内容

git reset --hard commit后面的内容

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Mybatis 多对一 按查询嵌套处理和按结果嵌套处理
下一篇:Ionic3 发布/订阅
相关文章

 发表评论

暂时没有评论,来抢沙发吧~