如何将远程存储库切换到不同的分支

发布于 2024-11-02 07:36:50 字数 415 浏览 1 评论 0原文

我有三个本地分支和三个远程分支,并且希望位于两个分支的同一分支上。

在本地:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤单情人 2024-11-09 07:36:50

下面是我切换并工作于 Git 存储库的远程分支的方法。

首先查看所有分支,只需在终端中输入以下命令:

git branch --all

然后您将看到本地和远程的所有分支。像这样的事情:

*master
remotes/origin/develop
remotes/origin/master
remotes/origin/web
remotes/origin/app

假设您想要切换到 remotes/origin/develop 分支。输入以下内容:

git checkout remotes/origin/develop

然后再次输入 gitbranch --all 以找到此内容:

*(detached from remotes/origin/develop)
master
remotes/origin/develop
remotes/origin/master
remotes/origin/web
remotes/origin/app

然后执行以下操作:

git checkout -b develop

从现在开始,您将完全在 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:

git branch --all

And then you will see the all the branches on local and remote. Something like this:

*master
remotes/origin/develop
remotes/origin/master
remotes/origin/web
remotes/origin/app

Let's pretend you want to switch to the remotes/origin/develop branch. Type following:

git checkout remotes/origin/develop

Then type git branch --all again to find this:

*(detached from remotes/origin/develop)
master
remotes/origin/develop
remotes/origin/master
remotes/origin/web
remotes/origin/app

And then just do:

git checkout -b develop

From now on, you are working on the remotes/origin/develop branch exactly.

鹿港小镇 2024-11-09 07:36:50
To switch to a remote repo
git branch -r ## list all the branches including the remote branches
git switch <branchname>
To switch to a remote repo
git branch -r ## list all the branches including the remote branches
git switch <branchname>
-柠檬树下少年和吉他 2024-11-09 07:36:50

据我所知,无法使用 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").

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文