上传项目到gitHub

创建好后开始提交本地项目代码如图

选中VCS选中图中的按钮如图所示

然后再选中Src点中add按钮如图所示

然后点中commit Directory后
打开终端进行项目根目录下键入以下 命令:
git remote add origin git@github.com:codegeekgao/Test.git(这里我写的自己的github地址,这里可以改成你自己的github项目)
git push -u origin master //将本地仓库的东西提交到地址是origin的地址,master分支下 

可能出现的报错异常

出现错误 error:src refspec master does not match any
引起该错误的原因是目录中没有文件,空目录是不能提交上去的.
解决办法:

在项目根目录下,创建README.md 文件即可

$ touch README.md
$ git add README,md
$ git commit –m’first commit’
$ git push origin master

进一步可能再次出现Permission denied (publickey). fatal: Could not read from remote repository.
这是因为本地没有ssh的密钥,生成密钥,在GitHub上添加这个ssh密钥即可,操作步骤如下:

1.首先,如果你没有ssh key的话,在ternimal下输入命令:ssh-keygen -t rsa -C "youremail@example.com"
youremail@example.com改为自己的邮箱即可,途中会让你输入密码啥的,不需要管,一路回车即可,会生成你的ssh key。
(如果重新生成的话会覆盖之前的ssh key。)
2. 若是window操作系统,会在C盘的用户目录下创建一个ssh目录,同理ios系统也是在用户目录下有ssh目录。
  • macos 查看ssh文件夹
  • window 查看ssh文件夹
用文本编辑器打开id_rsa.pub,复制里面的内容添加到github,如下图所示:

添加之后验证SSH的密钥

提示:Hi xxx! You've successfully authenticated, but GitHub does not provide shell  access.即为成功

提示出错信息:fatal: remote origin already exists. 解决办法如下:


然后再次输入git remote add origin git@github.com:codegeekgao/Test.git
git push -u origin master
然后会报以下错误:

! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:qzmly100/repository-.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这是因为:远程分支上存在本地分支中不存在的提交,往往是多人协作开发过程中遇到的问题,有如下两种解决方案:

  1. 可以先fetch然后在pull,把远程分支上的提交合并到本地分支之后再push,例如向master分支进行提交常用的命令如下:
# 从远程仓库fetch,取回更新后,会返回一个FETCH_HEAD
#这里可以查看master分支状态
git fetch origin master
# 将远程仓库与本地仓库合并,本地文件中多了README.md文件
git pull –-rebase origin master
# 再次执行提交master命令就会推送成功
git push -u origin master
  1. 如果你确定远程分支上那些提交都不需要了,那么直接git push origin master -f,强行让本地分支覆盖远程分支即可。
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐