这种push如何做?

两台电脑,pc1 pc2.

pc1 push project1 到 https://xxxx@github.com/xxxx/...

git init
git add  project1/
git commit -m "from pc1"  
git remote add origin  ttps://xxxx@github.com/xxxx/yyyy.git
git push -u origin master

成功了。

现在需要将pc2上面的project2 ,push到 https://xxxx@github.com/xxxx/...
下面在pc2上使用相同的代码

git init
git add  project2/
git commit -m "from pc1"  
git remote add origin  https://xxxx@github.com/xxxx/yyyy.git
git push -u origin master

报错

error: failed to push some refs to 'https://xxxx@github.com/xxxx/...'
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.

代码修改为

rm -rf .git
git init
git add  project2/
git commit -m "from pc1"  
git remote add origin  https://xxxx@github.com/xxxx/yyyy.git
git pull
git push -u origin master

报错:
error: failed to push some refs to 'https://xxxx@github.com/xxxx/...'
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.

代码继续修改为

rm -rf .git
git init
git add  project2/
git commit -m "from pc1"  
git remote add origin  https://xxxx@github.com/xxxx/yyyy.git
git pull origin master 

报错


    From https://xxxx@github.com/xxxx/yyyy.git
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories

git push -u origin master

报错

error: failed to push some refs to 'https://xxxx@github.com/xxxx/yyyy.git'

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.
请问,如何解决?

阅读 2.1k
1 个回答
rm -rf .git
git init
git remote add origin  https://xxxx@github.com/xxxx/yyyy.git
git pull origin master # 这一步,如果提示你有冲突,你要先解决冲突,再往下进行
git add  project2/
git commit -m "from pc1"  
git push -u origin master
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进