通过Git上传项目到GitHub
1.在GitHub上创建自己的项目仓库,https://github.com/new。Repository name与自己的项目名称保持一致

2.进入本地项目根目录,鼠标右键 Git Bash Here
(1)执行命令:git init

(2)将项目的所有文件添加到仓库中(注意 git add 命令后面有一个 .)
git add .
(3)将上一步add的文件提交到仓库
git commit -m "提交的注释说明"
(4)复制GitHub仓库地址

(5)将本地仓库关联到GitHub新建的仓库上
git remote add origin https://github.com/qiaohan9090/gdiih
如果执行上面的命令出现如下错误:
fatal: remote origin already exists.
执行:
git remote rm origin
git remote add origin https://github.com/qiaohan9090/gdiih
(6)使用pull命令
git pull origin master
(7)将本地仓库的文件上传到GitHub远程仓库
git push -u origin master
执行上面的命令是可能会出现以下错误:

fatal: HttpRequestException encountered.
▒▒▒▒▒▒▒▒ʱ▒▒▒▒
To https://github.com/qiaohan9090/gdiih
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/qiaohan9090/gdiih'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
出现错误的原因是因为我们在GitHUb上面创建仓库是生成了一个README.md的文件,而本地项目中没有这个文件,所以出现版本冲突
解决办法:
git pull origin master --allow-unrelated-histories
执行命令是可能会出现vim编辑,不用管,保存退出就行。(先按i键,然后按esc,输入:wq!,回车)
然后建议做完上一步之后再重新:
git add .
git commit -m '提交说明'
git push origin master

浙公网安备 33010602011771号