建立好后开始提交本地项目代码如图:
java
选中VCS选中图中的按钮如图所示:
ios
而后再选中Src点中add按钮如图所示:git
而后点中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
引发该错误的缘由是目录中没有文件,空目录是不能提交上去的.
解决办法:github
在项目根目录下,建立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密钥便可,操做步骤以下:web
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目录。
用文本编辑器打开id_rsa.pub,复制里面的内容添加到github,以下图所示:
添加以后验证SSH的密钥shell
提示:Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.即为成功
提示出错信息:fatal: remote origin already exists. 解决办法以下:macos
而后再次输入git remote add origin git@github.com:codegeekgao/Test.git
git push -u origin master
而后会报如下错误:ssh
! [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.
这是由于:远程分支上存在本地分支中不存在的提交,每每是多人协做开发过程当中遇到的问题,有以下两种解决方案:编辑器
# 从远程仓库fetch,取回更新后,会返回一个FETCH_HEAD #这里能够查看master分支状态 git fetch origin master # 将远程仓库与本地仓库合并,本地文件中多了README.md文件 git pull –-rebase origin master # 再次执行提交master命令就会推送成功 git push -u origin master