来自上游的主人,主题分支 - 我的

时间:2013-06-05 13:42:41

标签: git

我将一个回购分配到我的github帐户。

然后我做了

git remote add upstream git@github.com:********/*********.git

现在我有upstream遥控器 - 原件,origin - 我的叉子。

我的master分支正在跟踪origin/master

我永远不会推送到origin/master,因为我要做的所有拉取请求都来自主题分支。

与此同时,我会经常从upstream/master提取最新的更改,以便从中创建新主题。

所以我想以这样的方式配置git:

  • 我的本地分支master正在跟踪upstream/master
  • 当我在master分支并且git push时,这将失败,因为upstream是只读的。
  • 当我在master分支机构并且git pull时,我将从upstream/master提取最新更改,我将立即能够git checkout -b my-new-topic-branch分叉最新的upstream/master

对工作流程有何评论?如何为此设置git?

master我做了:

git branch -u upstream/master

但是当我切换到主题分支时:

git remote show origin
...
  Local refs configured for 'git push':
    master  pushes to master  (fast-forwardable)
...

更新

解决方案:

(c8cc3a6) » git branch -d master                                   
Deleted branch master (was c8cc3a6).

(c8cc3a6) » git branch --track master upstream/master
Branch master set up to track remote branch master from upstream.

(c8cc3a6) » git remote show origin
...
  Local refs configured for 'git push':
    master                       pushes to master                       (fast-forwardable)
...

(c8cc3a6) » git remote show upstream
...
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

(c8cc3a6) » git checkout master
Switched to branch 'master'

(master) » git pull
Already up-to-date.

(master) » git push
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

(master) » git checkout -b test-branch
Switched to a new branch 'test-branch'

(test-branch) » git push
...
To git@github.com:********/*******.git
 * [new branch]      HEAD -> test-branch

或者更容易理解的方式:

(test-branch) » git branch -d master
Deleted branch master (was c8cc3a6).

(test-branch) » git checkout -b master upstream/master  
Branch master set up to track remote branch master from upstream.
Switched to a new branch 'master'

1 个答案:

答案 0 :(得分:1)

在您本地存储库的.git/config中,将[branch "master"]部分设为如下所示:

[branch "master"]
remote = upstream
merge = refs/heads/master

这将处理项目1和3(跟踪和拉动配置)。我不确定是否有办法完美地完成第2项,但您可能会发现,因为upstream不是您的存储库,它会拒绝您的推送(除非该存储库的所有者允许随机贡献者推,我不确定可以在github上完成......)。