了解git:将分支连接到远程存储库 [英] Understanding git: connect branch to a remote repository
问题描述
repo
,它有一个分支 origin-master
,我想要做的是能够编辑仓库中的东西。 repo / origin-master< -------->克隆工作正常:
pre> mkdir repo&& cd回购&& git init
#当然不需要:
echomaster>大师&& git add master&& git ci -mmaster
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
#创建一个新文件:
echofor origin-master> orig-master&& git add orig-master&& git ci -morig-master
但是
git push origin
至git@github.com:< username> /testrepo.git
! [被拒绝] master - > master(非快速转发)
错误:未能将某些文件推送到'git@github.com:<用户名> /testrepo.git'
为了防止您丢失历史记录, - 前进更新被拒绝
在再次推送前合并远程更改(例如'git pull')。有关详细信息,请参阅git push --help的快速转发部分的
'注意事项。
如何告诉git如果我想推送到原点,我想推送本地分支 origin-master
至 origin / master
?
将您的默认推送行为设置为上游:
$ git config push.default上游
$ git push origin
git push origin
与 git push origin:
相同,默认情况下会推送所有匹配分支。您的origin-master分支不匹配,因此它会尝试匹配 的分支( master
)并将其推送到原点。 / p>
另外,您可以在每个远程的基础上指定 push
refspecs:
$ git config --add remote.origin.push origin-master:master
$ git push origin
另请参阅 git-push示例和 git-config 。
I have a repository on github, say testrepo. Now I'd like to set up a local repository repo
that has one branch origin-master
where I want do be able to edit things from the repository.
repo/origin-master <--------> origin/master
The cloning works fine:
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"
but
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.
How can I tell git that if I want to push to origin, I want to push the local branch origin-master
to origin/master
?
Set your default push behavior to upstream:
$ git config push.default upstream
$ git push origin
git push origin
is the same as git push origin :
, which pushes all "matching" branches by default. Your origin-master branch doesn't match, so it tries to take the branch that does match (master
) and push that to origin.
Alternatively, you can specify the push
refspecs on a per-remote basis:
$ git config --add remote.origin.push origin-master:master
$ git push origin
See also git-push examples and git-config.
这篇关于了解git:将分支连接到远程存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!