我在我的 github 帐户中创建了一个 repo。
然后我做了
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'