Git从某个分支更新master

时间:2021-10-09 16:25:46

While I'm in a branch B1 can I update the master from remote while staying in B1?
I.e. not doing

当我在分支B1时,我可以在B1期间从远程更新主设备吗?即没做

git checkout master
git pull
git checkout B1

But something shorter?

但更短的东西?

2 个解决方案

#1


2  

It's possible to get your local master updated without leaving your local branch by:

您可以通过以下方式更新本地主数据,而无需离开本地分支机构:

git pull origin master:master

What this command does is to pull the remote master and update the local master.

此命令的作用是拉取远程主服务器并更新本地主服务器。

Generally git pull origin pulls all the branches in origin. It's possible to get one single branch pulled by git pull origin <remote-branch>. Actually the last parameter is a refspec.

通常git pull origin会拉动所有分支。可以通过git pull origin 来获取一个单独的分支。实际上最后一个参数是refspec。

A refspec follows the format src:dst. In the case of git-pull, src refers to a remote branch and dst to a local branch. git pull origin master, will just pull the remote master but won't update the local one. git pull origin master:master, will pull the remote master and update the local one.

refspec遵循格式src:dst。在git-pull的情况下,src指的是远程分支,dst指向本地分支。 git pull origin master,只会拉远程主服务器但不会更新本地服务器。 git pull origin master:master,将拉远程主服务器并更新本地服务器。

#2


0  

You run:

你跑:

git fetch --all

or

要么

git remote update

After that, the remote master will in remote-tracking branch origin/master, you will be able to see its progress just like it were the local branch master. You can choose a time to merge/rebase the local master later.

之后,远程主站将在远程跟踪分支origin / master中,您将能够看到它的进度,就像它是本地分支主机一样。您可以稍后选择合并/重新绑定本地主服务器的时间。

Explanation: most probably you have a pair of remote-tracking branch origin/master and local branch master. master starts from from origin/master at some moment and contains local changes. git pull (1) updates origin/master and (2) merge or rebase the local modifications with origin/master progress. (1) can be done by git fetch I recommended, and (2) in current implementation requires checking out master anyway, even if the changes are trivial to merge.

说明:很可能你有一对远程跟踪分支origin / master和local branch master。 master在某个时刻从origin / master开始,包含本地更改。 git pull(1)更新origin / master和(2)合并或重新定义本地修改与origin / master进度。 (1)可以通过我推荐的git fetch来完成,并且(2)在当前实现中无论如何都需要检查master,即使这些更改很容易合并。

#1


2  

It's possible to get your local master updated without leaving your local branch by:

您可以通过以下方式更新本地主数据,而无需离开本地分支机构:

git pull origin master:master

What this command does is to pull the remote master and update the local master.

此命令的作用是拉取远程主服务器并更新本地主服务器。

Generally git pull origin pulls all the branches in origin. It's possible to get one single branch pulled by git pull origin <remote-branch>. Actually the last parameter is a refspec.

通常git pull origin会拉动所有分支。可以通过git pull origin 来获取一个单独的分支。实际上最后一个参数是refspec。

A refspec follows the format src:dst. In the case of git-pull, src refers to a remote branch and dst to a local branch. git pull origin master, will just pull the remote master but won't update the local one. git pull origin master:master, will pull the remote master and update the local one.

refspec遵循格式src:dst。在git-pull的情况下,src指的是远程分支,dst指向本地分支。 git pull origin master,只会拉远程主服务器但不会更新本地服务器。 git pull origin master:master,将拉远程主服务器并更新本地服务器。

#2


0  

You run:

你跑:

git fetch --all

or

要么

git remote update

After that, the remote master will in remote-tracking branch origin/master, you will be able to see its progress just like it were the local branch master. You can choose a time to merge/rebase the local master later.

之后,远程主站将在远程跟踪分支origin / master中,您将能够看到它的进度,就像它是本地分支主机一样。您可以稍后选择合并/重新绑定本地主服务器的时间。

Explanation: most probably you have a pair of remote-tracking branch origin/master and local branch master. master starts from from origin/master at some moment and contains local changes. git pull (1) updates origin/master and (2) merge or rebase the local modifications with origin/master progress. (1) can be done by git fetch I recommended, and (2) in current implementation requires checking out master anyway, even if the changes are trivial to merge.

说明:很可能你有一对远程跟踪分支origin / master和local branch master。 master在某个时刻从origin / master开始,包含本地更改。 git pull(1)更新origin / master和(2)合并或重新定义本地修改与origin / master进度。 (1)可以通过我推荐的git fetch来完成,并且(2)在当前实现中无论如何都需要检查master,即使这些更改很容易合并。