如何将远程存储库切换到不同的分支
我有三个本地分支和三个远程分支,并且希望位于两个分支的同一分支上。
在本地:
git branch
A
* B
master
git branch -r
origin/A
origin/B
origin/master
在远程:
git branch
A
B
* master
我能够提交、推送和拉取 B,但我的更新挂钩部署 master 而不是 B。我想是因为远程分支仍然设置掌握。我使用以下命令创建了分支 B:
git branch B
git checkout B
git push origin B
I have three local and three remote branches and want to be on the same branch on both.
On local:
git branch
A
* B
master
git branch -r
origin/A
origin/B
origin/master
On remote:
git branch
A
B
* master
I am able to commit, push and pull B, but my update hook deploys master instead of B. I suppose because the remote branch is still set to master. I created branch B using:
git branch B
git checkout B
git push origin B
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面是我切换并工作于 Git 存储库的远程分支的方法。
首先查看所有分支,只需在终端中输入以下命令:
然后您将看到本地和远程的所有分支。像这样的事情:
假设您想要切换到
remotes/origin/develop
分支。输入以下内容:然后再次输入
gitbranch --all
以找到此内容:然后执行以下操作:
从现在开始,您将完全在
remotes/origin/develop
分支上工作。Below is my method to switch and work for a remote branch of a Git repository.
Have a look for all the branches first, just input following command in the terminal:
And then you will see the all the branches on local and remote. Something like this:
Let's pretend you want to switch to the
remotes/origin/develop
branch. Type following:Then type
git branch --all
again to find this:And then just do:
From now on, you are working on the
remotes/origin/develop
branch exactly.据我所知,无法使用 git push 更改远程的当前分支。推送只会将本地更改复制到该存储库中。通常,您推送到的遥控器应该是
--bare
,没有工作目录(因此没有“当前分支”)。As far as I know, there's no way to change a remote's current branch with
git push
. Pushing will just copy your local changes up into that repository. Typically remotes you push to should be--bare
, without a working directory (and thus no "current branch").