[英]Push local Git branch to origin
I'm working on two machines and origin repo on third one (origin is accessible from the other two, no direct connection between machine1 and machine2). 我正在研究两台机器和第三台机器上的原始仓库(原点可以从其他两台进入,机器1和机器2之间没有直接连接)。
# Machine 1
$ git branch
master
* testing
cms
# Machine 2
$ git branch
* master
Now, I want to push the testing
branch to the origin and have it on machine2 too, so the final effect would be: 现在,我想将
testing
分支推送到原点并将其放在machine2上,因此最终的效果将是:
# Machine 2
$ git branch
* testing
master
I have tried: 我试过了:
# Machine 1
$ git push origin testing
# Machine 2
$ git pull origin testing # bunch of merge conflicts
$ git checkout -b testing origin/testing # errors too
Current state is: 目前的状态是:
# Machine 1
$ git branch -r
origin/HEAD -> origin/master
origin/master
origin/testing
How to do it? 怎么做?
My next question probably will be: how to delete the origin/testing
branch? 我的下一个问题可能是:如何删除
origin/testing
分支?
Instead of using git pull
(which fetches and merges), try git fetch
(which won't try to merge with your current branch on machine2, and cause conflicts): 而不是使用
git pull
(提取和合并),尝试git fetch
(它不会尝试与machine2上的当前分支合并,并导致冲突):
# Machine 1
$ git push origin testing
# Machine 2
$ git fetch origin testing
$ git checkout -b testing origin/testing
You have successfully pushed the testing branch to origin so now you just need to get the branch to machine2. 您已成功将测试分支推送到原点,因此现在您只需要将分支转到machine2。
Not sure of the state of teh repo on machine2 so I would delete the directory (Or create a new one to use) and just clone the repo on Machine2 and checkout testing ... 不确定机器2上的回购状态,所以我会删除目录(或者创建一个新的目录),然后在Machine2上克隆回购和结帐测试......
So on Machine2 in an empty dir (new or clean): 所以在Machine2中的空目录(新的或干净的):
$ git clone git@github/somewhere
$ git branch
* master
$ git checkout testing
# ...
# something about getting and switching
# ...
$ git branch
* testing
master
All you have to do is the following: 您所要做的就是以下内容:
On Machine 1 , deploy the remote branch and link the local testing branch to it: 在计算机1上 ,部署远程分支并将本地测试分支链接到它:
git push -u origin testing
On Machine 2 , deploy a local branch that's linked to the remote testing branch: 在计算机2上 ,部署链接到远程测试分支的本地分支:
git fetch origin && git checkout --track origin/testing
Now both local testing branches must be deployed and linked to the remote testing branch =) 现在必须部署两个本地测试分支并链接到远程测试分支=)
Now for deleting a remote branch you can simply try this : 现在删除远程分支,你可以试试这个:
git push origin --delete testing
or 要么
git push origin :testing
The original poster states: 原始海报说明:
My next question probably will be: how to delete the
origin/testing
branch?我的下一个问题可能是:如何删除
origin/testing
分支?
You have to be clear what you mean by that, because after you push testing
to the remote repo, there will also be a local remote-tracking branch called origin/testing
that keeps track of the last known status of the testing
branch on the remote. 你必须明确你的意思,因为在你将
testing
推送到远程仓库之后,还会有一个名为origin/testing
的本地远程跟踪分支,它跟踪远程testing
分支的最后已知状态。 。 You can find this remote-tracking branch under .git/refs/remotes/origin/
. 你可以在
.git/refs/remotes/origin/
下找到这个远程跟踪分支。
testing
and local origin/testing
branches testing
和本地origin/testing
分支 If you delete the branch on the remote with the following commands: 如果使用以下命令删除远程分支:
git push origin :testing
# Or
git push origin --delete testing
then the local remote-tracking branch origin/testing
will also be deleted for you automatically. 然后, 本地远程跟踪分支
origin/testing
也将自动删除。
origin/testing
branch origin/testing
分支 If for some reason you just wanted to delete the local remote-tracking branch origin/testing
, but not the testing
branch on the remote, then you can run the git branch -d
command with the --remotes
or -r
flag: 如果由于某种原因你只想删除本地远程跟踪分支
origin/testing
,而不是远程上的testing
分支,则可以使用--remotes
或-r
标志运行git branch -d
命令:
git branch --delete --remotes origin/testing
# Or shorter
git branch -dr origin/testing
If you get an error message that the branch can't be deleted because it hasn't been merged yet, then you can force the deletion by using the -D
flag instead of --delete
or -d
. 如果您收到一条错误消息,指出由于尚未合并分支而无法删除该分支,则可以使用
-D
标志而不是--delete
或-d
强制删除该分支。
My next question probably will be: how to delete the origin/testing branch?
我的下一个问题可能是:如何删除origin / testing分支?
To answer your next question: Come out of branch you intend to delete and run: 回答你的下一个问题:出来你打算删除并运行的分支:
git branch -d < branch_name > git branch -d <branch_name>
-d delete fully merged branch -d delete完全合并的分支
-D delete branch (even if not merged) -D delete分支(即使没有合并)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.