通过SSH上传本地代码到Github仓库

版权声明:来自MarieDreamer https://blog.csdn.net/qq_33514421/article/details/83048051

一、创建github账户、安装git(略)

二、新建仓库

1、新建

2、填写

 

三、生成SSH

1、先检查有没有生成过SSH

cd ~/.ssh

ls

 如果有 id_rsa、id_rsa.pub 两个文件,则表示已经生成过ssh。若没有,则在 “C盘/用户/用户名“(即用户目录)下打开命令行

ssh-keygen -C '[email protected]' -t rsa

接下来就生成了上述两个文件。

2、为 github 添加 ssh key

扫描二维码关注公众号,回复: 3594735 查看本文章

 

 将 id_rsa.pub 以文本形式打开,赋值内容粘贴到内容框里,为这个 ssh 添加 title 以便区分。

3、确认是否添加成功

在命令行中

ssh -T [email protected]

如果有 successfully 的提示表示成功。可以跳过下面步骤到第4步。但是这里我连接不成功,用以下命令查看debug发现是连接超时的原因。

ssh -T -v [email protected]

解决方法:

在用户目录中创建名为config的文本,内容如下

Host github.com
User [email protected]
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

只用把User项改成你的就行。再次运行 ssh -T [email protected] 发现运行成功。

 四、上传代码

最开始新建的仓库,复制地址

git clone 项目地址

在拉下来的git文件夹中加入你想上传的文件

进入项目文件夹

git init

git add .

git commit -m "你的注释"

git remote add origin 项目地址

如果出现错误 fatal: remote origin already exists

则使用命令 git remote rm origin,再执行一次 git remote add origin 项目地址

接着执行

git push origin master

最后查看你的仓库,发现代码已经上传到仓库了。

猜你喜欢

转载自blog.csdn.net/qq_33514421/article/details/83048051