我将一个回购分配到我的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'
答案 0 :(得分:1)
在您本地存储库的.git/config
中,将[branch "master"]
部分设为如下所示:
[branch "master"]
remote = upstream
merge = refs/heads/master
这将处理项目1和3(跟踪和拉动配置)。我不确定是否有办法完美地完成第2项,但您可能会发现,因为upstream
不是您的存储库,它会拒绝您的推送(除非该存储库的所有者允许随机贡献者推,我不确定可以在github上完成......)。