上传本地代码到gitHub

来源:互联网 发布:查询淘宝关键字搜索量 编辑:程序博客网 时间:2024/06/05 03:00

1.登录github 后 Create a new repository  创建成功后复制git地址

2.git init 本地文件 

3.git add .

4. 提交代码 git commit -m "***"

5.关联远程仓库 git remoteadd origin https://github.com/hetao1124/myweb.git

6.git pull origin master上传github之前,要先pull一下

7.gitpush -u origin master 上传代码到github远程仓库



报错:

To https://github.com/hetao1124/myweb.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/hetao1124/myweb.git'
hint: Updates were rejected because the tip of your current branch is behin
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文件不在本地代码目录中

可以通过如下命令进行代码合并【注:pull=fetch+merge]

git pull --rebase origin master

再执行语句 git push -u origin master即可完成代码上传到github