我有一个团队,我们正在开展一个项目。我们的一名团队成员在GitHub上创建了一个存储库,并将其他人添加为协作者。我的团队成员将我们的代码提交到此存储库。我在我的部分做了更改,当我尝试提交它时,我有一个错误。如何将更改提交到我是协作者的存储库?
这就是我所做的:
git remote add origin https://github.com/xxx/xxx.git (added a repository where I'm a collaborator)
`git push origin master
To https://github.com/xxx/xxx.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/xxx/xxx.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
warning: no common commits
remote: Counting objects: 145, done.
remote: Compressing objects: 100% (60/60), done.
remote: Total 145 (delta 67), reused 145 (delta 67), pack-reused 0
Receiving objects: 100% (145/145), 55.90 KiB | 0 bytes/s, done.
Resolving deltas: 100% (67/67), done.
From https://github.com/xxx/xxx
* branch master -> FETCH_HEAD
* [new branch] master -> or/master
fatal: refusing to merge unrelated histories
我只是想更新我的部分并将其提交到存储库。我没有自己的存储库。
谢谢
答案 0 :(得分:3)
看起来您的两个主分支已经分歧。
# HEAD at your master
$ git checkout master
# your master on a new branch
$ git checkout -b diverged.master
# get origin's master
$ git checkout master
$ git fetch origin master
$ git reset --hard origin/master
# Create a new branch for the diverged feature
$ git checkout -b feature.branch
# Merge your diverged changes into the new feature branch
$ git merge diverged.master
# Do any conflict resolutions
# Merge feature branch to master
$ git checkout master
$ git merge feature.branch
# Push to remote
$ git push origin master
修改强>
我错过了关于这是一个全新的回购的部分..让这更容易
# HEAD at your master
$ git checkout master
# your master on a new branch
$ git checkout -b diverged.master
# delete master branch
# git branch -D master
# pull master from origin
$ git pull origin master
# HEAD at origin's master
$ git checkout origin master
$ git pull # for good measure
# merge your changes
$ git merge diverged.master
# push your changes
$ git push origin master