将代码上传至github方法及报错归类

本地项目根目录下,建立本地git仓库

git init

将项目的所有文件添加到仓库中,想添加某个特定的文件,只需把.换成特定的文件名即可

git add .

 将add的文件commit到仓库

git commit -m'备注'

 将本地的仓库关联到你的github远程仓库

git remote add origin git@github.com:HelloVansal/test.git

代码上传github之前,要先pull一下

git pull origin master

上传代码到github远程仓库

git push -u origin master

一些报错归类

fatal: remote origin already exists  远程仓库已存在

先删除远程 Git 仓库

git remote rm origin

再添加远程 Git 仓库

git remote add origin git@github.com:HelloVansal/test.git

如果执行 git remote rm origin 报错的话,我们可以直接删除本地的.git文件夹重新执行一遍git init和后面的代码

 

error: failed to push some refs to 'git@github.com:HelloVansal/test.git'

在建立github远程仓库时,不要打勾下面这句话,

Initialize this repository with a README

This will let you immediately clone the repository to your computer. Skip this step if you’re importing an existing repository.

这句话意思是,用一个readme初始化这个仓库

他会使你可以立即克隆这个仓库当你的电脑,如果你要导入一个已存在的工程请跳过他

所以如果你的仓库已建立,就不要打勾

 

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

fatal: Could not read from remote repository.Please make sure you have the correct access rights and the repository exists.

出现这个问题是因为没有在github账号添加SSH key

解决方法如下:

1.在终端输入。

ssh-keygen -t rsa -C "username" (注:username为你git上的用户名),一直按回车即可

SSH key就生成了。文件目录就是:/Users/username/.ssh/id_rsa.pub.

将id_rsa.pub.中的内容添加到github账户设置里边的SSH keys即可,就可以执行接下来的其他命令了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风里有诗句哈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值