关于如何将本地的仓库代码提交到github上
程序员文章站
2022-03-09 19:37:08
...
当我们在github上构建好自己的仓库的时候,我们可以使用下面的命令来进行提交
git init
git add .
git commit -m "first commit"
git remote add origin https://xxx.xxx.xxx
git push -u origin master
可能你会遇到下面的问题
$ git push -u origin master
得到下面的反馈,在github上有你没有文件,需要你先pull下来后再进行上传
To https://github.com/ruanjiayu/RabbitMQ.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/ruanjiayu/RabbitMQ.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 origin master
提示我两个分支没有任何的交际,不能在本地进行合并。
From https://github.com/ruanjiayu/RabbitMQ
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
解决的办法就是
git pull -f origin master --allow-unrelated-histories
这样就可以把无关的分支合并了
注意上述出现问题的原因是,你的github上有文件,如新建的仓库有一个readme.md,但是本地仓库没有导致的
上一篇: 硬盘双击无法打开的问题该怎么办