准备工作
- 下载安装Git工具(这里我以2.9.0版本做参考)
Git2.9.0百度云下载地址:Git2.9.0下载地址 密码:7dib
- 若未注册GitHub,请先注册
GitHub地址:GitHub官方地址
步骤
1.创建本地项目(这点不做过多阐述)
注意:建议在这一步的时候先配置好.gitignore文件,用于过滤上传文件,如图下:

2.开始初始化git
- 打开文件管理器,找到本地项目文件,右键点击Git Bash Here

- 初始化完成后,会在本地项目生成.git文件夹

- 然后添加要提交的项目文件,由于第一次上传 我们上传全部文建, 执行的命令行:git add .
- 添加项目文件完成后,先提交到本地仓库,执行的命令行:git commit -m "上传备注"

- 开始创建远程仓库:
** 进入GitHub,新建远程仓库

** 填入将要新建的远程仓库信息

** 复制远程仓库地址

- 关联远程仓库,命令行:git remote add origin 远程仓库地址
** 查询地址是否关联完成: git remote -v

- 提交此次的操作到关联的远程仓库,命令行:git push -u origin master
** 如果push推送成功,则为下图所示结果:

** 有的小伙伴们会经常遇见下图这种问题:

此类error错误出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去.
解决办法如下:
先把远程仓库的文件pull到本地,命令行:git pull --rebase origin master
然后再次push推送到远程仓库 git push -u origin master

有的人使用这个命令还是会出现这样的问题:
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
如图:

解决办法:再次执行git remote add origin 远程仓库地址 然后 git push origin master
网友评论