在上传至GitHub之前
-
先确保已有自己的GitHub账号
-
在GitHub中创建一个新的仓库
创建好后
第一步
在本地项目更目录中初始化
PS G:\react\reactProject\umi3-antd4> git init
Initialized empty Git repository in G:/react/reactProject/umi3-antd4/.git/
第二步
提交本地代码至本地仓库
git add . // 提交所有文件至暂存区
git commit -m '描述内容' // 将暂存区的文件提交至本地仓库
第三步
首先复制远程仓库地址
连接远程仓库
git remote add <远程仓库地址>
第四步
如果现在向Git上提交代码的话会报一下错误
PS G:\react\reactProject\umi3-antd4> git push -u origin master
To https://github.com/UseGitH/umi.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/UseGitH/umi.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.
所以在提交之前我们应该先拉去一下远程仓库的代码,运行命令
git pull --rebase origin master
运行命令后会让我们输入Git的账号秘密
fatal: HttpRequestException encountered.
发送请求时出错。
Username for 'https://github.com':
Password for 'https://UseGitH@github.com':
输入账号密码后的结果
From https://github.com/UseGitH/umi
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
warning: unable to access 'mock/.gitattributes': Permission denied
warning: unable to access 'mock/.gitattributes': Permission denied
Applying: 搭建umi3脚手架
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
CONFLICT (add/add): Merge conflict in README.md
Auto-merging README.md
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch' to see the failed patch
Patch failed at 0001 ***
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
然后再运行一下命令,重新拉去一下
git add .
git rebase --continue
第五步
最后运行命令提交本地仓库代码
git push -u origin master