我在 github 上有一个存储库,比如 testrepo。现在我想建立一个本地存储库repo
,它有一个分支origin-master
,我希望能够从存储库中编辑内容。
repo/origin-master <--------> origin/master
克隆工作正常:
mkdir repo && cd repo && git init
# not necessary of course:
echo "master" > master && git add master && git ci -m "master"
git remote add origin git@github.com:<username>/testrepo.git
git fetch origin
git branch --set-upstream origin-master origin/master
git checkout origin-master
# create a new file:
echo "for origin-master" > orig-master && git add orig-master && git ci -m "orig-master"
但
git push origin
To git@github.com:<username>/testrepo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:<username>/testrepo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
我如何告诉 git,如果我想推送到 origin,我想将本地分支推origin-master
送到origin/master
?