[英]How do I check out a remote Git branch?
Somebody pushed a branch called test
with git push origin test
to a shared repository.有人使用
git push origin test
名为test
的分支推送到了共享存储库。 I can see the branch with git branch -r
.我可以看到带有
git branch -r
的分支。 How do I check out the remote test
branch?如何签出远程
test
分支? I've tried:我试过了:
git checkout test
, which does nothing git checkout test
,什么都不做git checkout origin/test
gives * (no branch)
git checkout origin/test
给出* (no branch)
The answer has been split depending on whether there is one remote repository configured or multiple.答案已根据配置的远程存储库是一个还是多个而有所不同。 The reason for this is that for the single remote case, some of the commands can be simplified as there is less ambiguity.
这样做的原因是,对于单个远程情况,一些命令可以简化,因为歧义较少。
Updated for Git 2.23: For older versions, see the section at the end.针对 Git 2.23 更新:对于旧版本,请参阅最后的部分。
In both cases, start by fetching from the remote repository to make sure you have all the latest changes downloaded.在这两种情况下,首先从远程存储库获取以确保您已下载所有最新更改。
$ git fetch
This will fetch all of the remote branches for you.这将为您获取所有远程分支。 You can see the branches available for checkout with:
您可以通过以下方式查看可用于结帐的分支:
$ git branch -v -a
...
remotes/origin/test
The branches that start with remotes/*
can be thought of as read only copies of the remote branches.以
remotes/*
开头的分支可以被认为是远程分支的只读副本。 To work on a branch you need to create a local branch from it.要在分支上工作,您需要从它创建一个本地分支。 This is done with the Git command
switch
(since Git 2.23) by giving it the name of the remote branch (minus the remote name):这是通过 Git 命令
switch
(从 Git 2.23 开始)通过为其指定远程分支的名称(减去远程名称)来完成的:
$ git switch test
In this case Git is guessing (can be disabled with --no-guess
) that you are trying to checkout and track the remote branch with the same name.在这种情况下,Git 猜测(可以使用
--no-guess
禁用)您正在尝试签出并跟踪具有相同名称的远程分支。
In the case where multiple remote repositories exist, the remote repository needs to be explicitly named.在存在多个远程存储库的情况下,需要显式命名远程存储库。
As before, start by fetching the latest remote changes:和以前一样,首先获取最新的远程更改:
$ git fetch origin
This will fetch all of the remote branches for you.这将为您获取所有远程分支。 You can see the branches available for checkout with:
您可以通过以下方式查看可用于结帐的分支:
$ git branch -v -a
With the remote branches in hand, you now need to check out the branch you are interested in with -c
to create a new local branch:有了远程分支,您现在需要使用
-c
检查您感兴趣的分支以创建一个新的本地分支:
$ git switch -c test origin/test
For more information about using git switch
:有关使用
git switch
的更多信息:
$ man git-switch
I also created the image below for you to share the differences, look at how to fetch works, and also how it's different to pull:我还创建了下面的图像供您分享差异,看看如何获取工作,以及拉取的不同之处:
git switch
was added in Git 2.23, prior to this git checkout
was used to switch branches. git switch
是在 Git 2.23 中添加的,在此之前git checkout
用于切换分支。
To checkout out with only a single remote repository:要仅使用单个远程存储库签出:
git checkout test
if there there are multiple remote repositories configured it becomes a bit longer如果配置了多个远程存储库,它会变得更长一些
git checkout -b test <name of remote>/test
Sidenote: With modern Git (>= 1.6.6 ), you are able to use just旁注:使用现代 Git (>= 1.6.6 ),您可以使用
git checkout test
(note that it is 'test' not 'origin/test') to perform magical DWIM -mery and create local branch 'test' for you, for which upstream would be remote-tracking branch 'origin/test'. (请注意,它是“测试”而不是“起源/测试”)执行神奇的 DWIM -mery 并为您创建本地分支“测试”,上游将是远程跟踪分支“起源/测试”。
The * (no branch)
in git branch
output means that you are on unnamed branch, in so called "detached HEAD" state (HEAD points directly to commit, and is not symbolic reference to some local branch). git branch
输出中的* (no branch)
表示您在未命名的分支上,处于所谓的“分离 HEAD”状态(HEAD 直接指向提交,而不是对某个本地分支的符号引用)。 If you made some commits on this unnamed branch, you can always create local branch off current commit:如果你在这个未命名的分支上做了一些提交,你总是可以从当前提交创建本地分支:
git checkout -b test HEAD
A more modern approach as suggested in the comments:评论中建议的更现代的方法:
@Dennis:
git checkout <non-branch>
, for examplegit checkout origin/test
results in detached HEAD / unnamed branch, whilegit checkout test
orgit checkout -b test origin/test
results in local branchtest
(with remote-tracking branchorigin/test
as upstream ) – Jakub Narębski Jan 9 '14 at 8:17@Dennis:
git checkout <non-branch>
,例如git checkout origin/test
结果在分离的 HEAD / 未命名分支中,而git checkout test
或git checkout -b test origin/test
结果在本地分支test
(带有远程跟踪分支origin/test
作为上游) – Jakub Narębski 2014 年 1 月 9 日 8:17
emphasis on git checkout origin/test
强调
git checkout origin/test
In this case, you probably want to create a local test
branch which is tracking the remote test
branch:在这种情况下,您可能希望创建一个跟踪远程
test
分支的本地test
分支:
$ git branch test origin/test
In earlier versions of git
, you needed an explicit --track
option, but that is the default now when you are branching off a remote branch.在早期版本的
git
中,您需要一个显式的--track
选项,但现在当您从远程分支分支时,这是默认选项。
To create the local branch and switch to it, use:要创建本地分支并切换到它,请使用:
$ git checkout -b test origin/test
While the first and selected answer is technically correct , there's the possibility you have not yet retrieved all objects and refs from the remote repository.虽然第一个和选定的答案在技术上是正确的,但您可能尚未从远程存储库中检索所有对象和引用。 If that is the case, you'll receive the following error:
如果是这种情况,您将收到以下错误:
$ git checkout -b remote_branch origin/remote_branch
fatal: git checkout: updating paths is incompatible with switching branches.
致命:git checkout:更新路径与切换分支不兼容。
Did you intend to checkout 'origin/remote_branch' which can not be resolved as commit?您是否打算签出无法解析为提交的“origin/remote_branch”?
If you receive this message, you must first do a git fetch origin
where origin
is the name of the remote repository prior to running git checkout remote_branch
.如果您收到此消息,您必须先执行
git fetch origin
,其中origin
是远程存储库的名称,然后再运行git checkout remote_branch
。 Here's a full example with responses:这是一个完整的响应示例:
$ git fetch origin
remote: Counting objects: 140, done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 69 (delta 36), reused 66 (delta 33)
Unpacking objects: 100% (69/69), done.
From https://github.com/githubuser/repo-name
e6ef1e0..5029161 develop -> origin/develop
* [new branch] demo -> origin/demo
d80f8d7..359eab0 master -> origin/master
$ git checkout demo
Branch demo set up to track remote branch demo from origin.
Switched to a new branch 'demo'
As you can see, running git fetch origin
retrieved any remote branches we were not yet setup to track on our local machine.如您所见,运行
git fetch origin
检索了我们尚未设置为在本地机器上跟踪的任何远程分支。 From there, since we now have a ref to the remote branch, we can simply run git checkout remote_branch
and we'll gain the benefits of remote tracking.从那里开始,由于我们现在有一个远程分支的引用,我们可以简单地运行
git checkout remote_branch
,我们将获得远程跟踪的好处。
I tried the above solution, but it didn't work.我尝试了上述解决方案,但没有奏效。 Try this, it works:
试试这个,它有效:
git fetch origin 'remote_branch':'local_branch_name'
This will fetch the remote branch and create a new local branch (if not exists already) with name local_branch_name
and track the remote one in it.这将获取远程分支并创建一个名为
local_branch_name
的新本地分支(如果不存在)并跟踪其中的远程分支。
This will DWIM for a remote not named origin ( documentation ):这将为未命名的远程DWIM原点( 文档):
$ git checkout -t remote_name/remote_branch
To add a new remote, you will need to do the following first:要添加新的遥控器,您需要先执行以下操作:
$ git remote add remote_name location_of_remote
$ git fetch remote_name
The first tells Git the remote exists, the second gets the commits.第一个告诉 Git 远程存在,第二个获取提交。
Use:利用:
git checkout -b <BRANCH-NAME> <REMOTE-NAME>/<BRANCH-NAME>
Other answers do not work with modern Git in my benign case.在我的良性案例中,其他答案不适用于现代 Git。 You might need to pull first if the remote branch is new, but I haven't checked that case.
如果远程分支是新的,您可能需要先提取,但我没有检查过这种情况。
You basically see the branch, but you don't have a local copy yet!...您基本上看到了分支,但是您还没有本地副本!...
You need to fetch
the branch...您需要
fetch
分支...
You can simply fetch and then checkout to the branch, use the one line command below to do that:您可以简单地获取然后结帐到分支,使用下面的一行命令来执行此操作:
git fetch && git checkout test
I also created the image below for you to share the differences, look at how fetch
works and also how it's different to pull
:我还为您创建了下面的图像来分享差异,看看
fetch
的工作原理以及pull
的不同之处:
To clone a Git repository, do:要克隆 Git 存储库,请执行以下操作:
git clone <either ssh url /http url>
The above command checks out all of the branches, but only the master
branch will be initialized.上面的命令检查出所有的分支,但只有
master
分支会被初始化。 If you want to checkout the other branches, do:如果要检查其他分支,请执行以下操作:
git checkout -t origin/future_branch (for example)
This command checks out the remote branch, and your local branch name will be same as the remote branch.此命令检出远程分支,您的本地分支名称将与远程分支相同。
If you want to override your local branch name on checkout:如果您想在结帐时覆盖您的本地分支名称:
git checkout -t -b enhancement origin/future_branch
Now your local branch name is enhancement
, but your remote branch name is future_branch
.现在您的本地分支名称是
enhancement
,但您的远程分支名称是future_branch
。
You can try你可以试试
git fetch remote
git checkout --track -b local_branch_name origin/branch_name
or或者
git fetch
git checkout -b local_branch_name origin/branch_name
I was stuck in a situation seeing error: pathspec 'desired-branch' did not match any file(s) known to git.
我陷入了看到
error: pathspec 'desired-branch' did not match any file(s) known to git.
for all of the suggestions above.对于上述所有建议。 I'm on Git version 1.8.3.1.
我在 Git 版本 1.8.3.1 上。
So this worked for me :所以这对我有用:
git fetch origin desired-branch
git checkout -b desired-branch FETCH_HEAD
The explanation behind is that I've noticed that when fetching the remote branch, it was fetched to FETCH_HEAD :背后的解释是我注意到在获取远程分支时,它被提取到了FETCH_HEAD :
git fetch origin desired-branch
From github.com:MYTEAM/my-repo
* branch desired-branch -> FETCH_HEAD
First, you need to do:首先,您需要执行以下操作:
git fetch
# If you don't know about branch name git fetch
# 如果你不知道分支名称
git fetch origin branch_name
Second, you can check out remote branch into your local by:其次,您可以通过以下方式将远程分支签出到本地:
git checkout -b branch_name origin/branch_name
-b
will create new branch in specified name from your selected remote branch. -b
将从您选择的远程分支以指定名称创建新分支。
我使用以下命令:
git checkout --track origin/other_remote_branch
Commands命令
git fetch --all
git checkout -b <ur_new_local_branch_name> origin/<Remote_Branch_Name>
are equal to等于
git fetch --all
and then接着
git checkout -b fixes_for_dev origin/development
Both will create a latest fixes_for_dev
from development
两者都将从
development
中创建一个latest fixes_for_dev
Simply run git checkout
with the name of the remote branch.只需使用远程分支的名称运行
git checkout
。 Git will automatically create a local branch that tracks the remote one: Git 将自动创建一个本地分支来跟踪远程分支:
git fetch
git checkout test
However, if that branch name is found in more than one remote, this won't work as Git doesn't know which to use.但是,如果在多个远程中找到该分支名称,这将不起作用,因为 Git 不知道该使用哪个。 In that case you can use either:
在这种情况下,您可以使用:
git checkout --track origin/test
or或者
git checkout -b test origin/test
In 2.19 , Git learned the checkout.defaultRemote
configuration, which specifies a remote to default to when resolving such an ambiguity.在2.19中,Git 学习了
checkout.defaultRemote
配置,该配置指定了解决此类歧义时默认使用的远程。
If the branch is on something other than the origin
remote I like to do the following:如果分支位于
origin
远程以外的其他位置,我喜欢执行以下操作:
$ git fetch
$ git checkout -b second/next upstream/next
This will checkout the next
branch on the upstream
remote in to a local branch called second/next
.这会将
upstream
远程上的next
分支检出到名为second/next
的本地分支中。 Which means if you already have a local branch named next it will not conflict.这意味着如果您已经有一个名为 next 的本地分支,它将不会发生冲突。
$ git branch -a
* second/next
remotes/origin/next
remotes/upstream/next
None of these answers worked for me.这些答案都不适合我。 This worked:
这有效:
git checkout -b feature/branch remotes/origin/feature/branch
git fetch && git checkout your-branch-name
The git remote show <origin name>
command will list all branches (including un-tracked branches). git remote show <origin name>
命令将列出所有分支(包括未跟踪的分支)。 Then you can find the remote branch name that you need to fetch.然后你可以找到你需要获取的远程分支名称。
Example:例子:
$ git remote show origin
Use these steps to fetch remote branches:使用以下步骤获取远程分支:
git fetch <origin name> <remote branch name>:<local branch name>
git checkout <local branch name > (local branch name should the name that you given fetching)
Example:例子:
$ git fetch origin test:test
$ git checkout test
git branch -r
says the object name is invalid, because that branch name isn't in Git's local branch list. git branch -r
表示对象名称无效,因为该分支名称不在 Git 的本地分支列表中。 Update your local branch list from origin with:从 origin 更新您的本地分支列表:
git remote update
And then try checking out your remote branch again.然后尝试再次检查您的远程分支。
This worked for me.这对我有用。
I believe git fetch
pulls in all remote branches, which is not what the original poster wanted.我相信
git fetch
会拉入所有远程分支,这不是原始发布者想要的。
Fetch from the remote and checkout the branch.从远程获取并签出分支。
git fetch <remote_name> && git checkout <branch_name>
Eg:例如:
git fetch origin && git checkout feature/XYZ-1234-Add-alerts
git fetch origin && git checkout feature/XYZ-1234-Add-alerts
Other guys and gals give the solutions, but maybe I can tell you why.其他人给出了解决方案,但也许我可以告诉你原因。
git checkout test which does nothing
git checkout test 什么都不做
Does nothing
doesn't equal doesn't work
, so I guess when you type 'git checkout test' in your terminal and press enter key, no message appears and no error occurs. Does nothing
不等于doesn't work
,所以我猜当您在终端中键入“git checkout test”并按回车键时,不会出现任何消息,也不会发生错误。 Am I right?我对吗?
If the answer is 'yes', I can tell you the cause.如果答案是“是”,我可以告诉你原因。
The cause is that there is a file (or folder) named 'test' in your work tree.原因是您的工作树中有一个名为“test”的文件(或文件夹)。
When git checkout xxx
parsed,当
git checkout xxx
解析时,
xxx
as a branch name at first, but there isn't any branch named test. xxx
视为分支名称,但没有任何名为 test 的分支。xxx
is a path, and fortunately (or unfortunately), there is a file named test.xxx
是一个路径,幸运的是(或不幸地),有一个名为 test.txt 的文件。 So git checkout xxx
means discard any modification in xxx
file.git checkout xxx
意味着丢弃xxx
文件中的任何修改。xxx
either, then Git will try to create the xxx
according to some rules.xxx
的文件,那么 Git 会尝试根据一些规则创建xxx
。 One of the rules is create a branch named xxx
if remotes/origin/xxx
exists.remotes/origin/xxx
存在,则创建一个名为xxx
的分支。To get newly created branches获取新创建的分支
git fetch
To switch into another branch切换到另一个分支
git checkout BranchName
git checkout -b "Branch_name" [ B means Create local branch] git checkout -b "Branch_name" [B 表示创建本地分支]
git branch --all git 分支--全部
git checkout -b "Your Branch name" git checkout -b "你的分行名称"
git branch git 分支
git pull origin "Your Branch name" git pull origin "你的分支名称"
successfully checkout from the master branch to dev branch成功从 master 分支结帐到 dev 分支
I used that one:我用过那个:
git clean -fxd # removes untracked (new added plus ignored files)
git fetch
git checkout {branchname}
git reset --hard origin/{branchname} # removes staged and working directory changes
我总是这样做: git fetch origin && git checkout --track origin/branch_name
You can start tracking all remote branches with the following Bash script:您可以使用以下 Bash 脚本开始跟踪所有远程分支:
#!/bin/bash
git fetch --all
for branch in `git branch -r --format="%(refname:short)" | sed 's/origin\///'`
do git branch -f --track "$branch" "origin/$branch"
done
Here is also a single-line version:这里也是单行版本:
git fetch --all; for branch in `git branch -r --format="%(refname:short)" | sed 's/origin\///'`; do git branch --track "$branch" "origin/$branch" ; done ;
For us, it seems the remote.origin.fetch
configuration gave a problem.对我们来说,
remote.origin.fetch
配置似乎出了问题。 Therefore, we could not see any other remote branches than master
, so git fetch [--all]
did not help.因此,除了
master
之外,我们看不到任何其他远程分支,因此git fetch [--all]
没有帮助。 Neither git checkout mybranch
nor git checkout -b mybranch --track origin/mybranch
did work, although it certainly was at remote. git checkout mybranch
和git checkout -b mybranch --track origin/mybranch
没有工作,尽管它肯定是在远程。
The previous configuration only allowed master
to be fetched:之前的配置只允许获取
master
:
$ git config --list | grep fetch
remote.origin.fetch=+refs/heads/master:refs/remotes/origin/master
Fix it by using *
and fetch the new information from origin:使用
*
修复它并从源获取新信息:
$ git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
$ git fetch
...
* [new branch] ...
...
Now we could git checkout
the remote branch locally.现在我们可以在本地
git checkout
远程分支。
No idea how this config ended up in our local repo.不知道这个配置是如何在我们的本地仓库中结束的。
For some reason, I couldn't do:由于某种原因,我不能这样做:
$ git checkout -b branch-name origin/branch-name
It was throwing the error:它抛出错误:
fatal: 'origin/branch-name' is not a commit and a branch 'branch-name' cannot be created from it
I had to do:我必须做:
$ git checkout -b branch-name commit-sha
to get all remote branches use this :让所有远程分支使用这个:
git fetch --all
then checkout to the branch :然后结帐到分支:
git checkout test
TL;DR using git switch
rather than git checkout
, more detail in this link TL;DR 使用
git switch
而不是git checkout
, 此链接中的更多详细信息
I think the answer is obsolete.我认为答案已经过时了。 Git split some function of
checkout
to switch
and restore
now. Git拆分了
checkout
的一些功能,现在可以switch
和restore
。
The following is my summary:以下是我的总结:
If you want to update something for remote branch, you should create local branch to "track" remote branch.如果你想为远程分支更新一些东西,你应该创建本地分支来“跟踪”远程分支。 You can update anything you want in local and finally push to remote.
您可以在本地更新您想要的任何内容,最后推送到远程。 If you checkout to remote branch directly after cloning your repository, you may see "detached HEAD" status and following message from Git:
如果您在克隆存储库后直接签出到远程分支,您可能会看到“分离的 HEAD”状态和来自 Git 的以下消息:
Note: switching to 'origin/asd'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at d3e1083 Update a
So how to create local branch to track remote branch?那么如何创建本地分支来跟踪远程分支呢?
To create local branch to track remote branch, you can use git checkout <remote branch name>
or git switch <remote branch name>
.要创建本地分支来跟踪远程分支,可以使用
git checkout <remote branch name>
或git switch <remote branch name>
。 If you have a file or folder has same name as your remote branch name, git checkout
would output some error message, but git switch
can work normarly!如果你有一个文件或文件夹与你的远程分支名称相同,
git checkout
会输出一些错误信息,但git switch
可以正常工作!
example:例子:
remotes/origin/asd
, and we also have the file name asd
remotes/origin/asd
,我们还有文件名asd
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/asd
remotes/origin/ereres
remotes/origin/master
remotes/origin/zxc
$ ls
a asd
git checkout
command to create local branch to track remote branchgit checkout
命令创建本地分支来跟踪远程分支,Git 应该会输出一些错误消息$ git checkout asd
fatal: 'asd' could be both a local file and a tracking branch.
Please use -- (and optionally --no-guess) to disambiguate
git switch
!git switch
就可以了!$ git switch ereres
Branch 'ereres' set up to track remote branch 'ereres' from 'origin'.
Switched to a new branch 'ereres'
$ git branch -vv
* ereres 3895036 [origin/ereres] Update a
master f9e24a9 [origin/master] Merge branch 'master' of
It seems to my that no one suggested the simplest way (or maybe I'm too dumb to think this is "a way" ).在我看来,没有人提出最简单的方法(或者我可能太愚蠢了,无法认为这是“一种方法” )。 But anyway, have you tried this?
但无论如何,你试过这个吗?
$ git pull origin remoteBranchName
$ git switch remoteBranchName
This worked for me in the same case (a branch created on the remote after my last pull request).这在同样的情况下对我有用(在我最后一次拉取请求之后在远程创建的分支)。
If the remote branch name begins with special characters you need to use single quotes around it in the checkout command, or else Git won't know which branch you are talking about.如果远程分支名称以特殊字符开头,您需要在 checkout 命令中使用单引号,否则 Git 将不知道您在谈论哪个分支。
For example, I tried to checkout a remote branch named #9773
, but the command didn't work properly, as shown in the picture below:例如,我尝试签出一个名为
#9773
的远程分支,但该命令无法正常工作,如下图所示:
For some reason, I wondered if the sharp symbol (#) could have something to do with it, and then I tried surrounding the branch name with single quotes, like '#9773'
rather than just #9773
, and fortunately it worked fine.出于某种原因,我想知道尖锐符号 (#) 是否与它有关,然后我尝试用单引号将分支名称括起来,例如
'#9773'
而不仅仅是#9773
,幸运的是它运行良好。
git checkout -b '#9773' origin/'#9773'
Just run these two commands and you should be good to go.只需运行这两个命令,您就可以开始了。
git checkout <branch-name>
git pull <remote> <branch-name>
git fetch --all
would fetch all the remote branches to your local会将所有远程分支提取到您的本地
git checkout test
would switch you to the test branch会将您切换到测试分支
Please follow the command to create an empty folder.请按照命令创建一个空文件夹。 Enter that and use this command:
输入并使用以下命令:
saifurs-Mini:YO-iOS saifurrahman$ git clone your_project_url
Cloning into 'iPhoneV1'...
remote: Counting objects: 34230, done.
remote: Compressing objects: 100% (24028/24028), done.
remote: Total 34230 (delta 22212), reused 15340 (delta 9324)
Receiving objects: 100% (34230/34230), 202.53 MiB | 294.00 KiB/s, done.
Resolving deltas: 100% (22212/22212), done.
Checking connectivity... done.
saifurs-Mini:YO-iOS saifurrahman$ cd iPhoneV1/
saifurs-Mini:iPhoneV1 saifurrahman$ git checkout 1_4_0_content_discovery
Branch 1_4_0_content_discovery set up to track remote branch 1_4_0_content_discovery from origin.
Switched to a new branch '1_4_0_content_discovery'
Use fetch
to pull all your remote使用
fetch
拉取你所有的遥控器
git fetch --all
To list remote branches:列出远程分支:
git branch -r
For list all your branches列出你所有的分支
git branch -l
>>outpots like-
* develop
test
master
To checkout/change a branch结帐/更改分支
git checkout master
There are many alternatives, for example:有很多选择,例如:
Alternative 1:备选方案 1:
git fetch && git checkout test
It's the most simple way.
这是最简单的方法。
Alternative 2:备选方案 2:
git fetch git checkout test
It's the same but in two steeps.
它是相同的,但在两个陡峭的地方。
您可以在本地添加新的分支test
,然后使用:
git branch --set-upstream-to=origin/test test
Not sure, I keep doing this day in and day out.不确定,我每天都在做这个。 Following command works like gem.
以下命令像 gem 一样工作。
dev being the branch you want to checkout. dev是您要结帐的分支。
git fetch && git checkout dev
git fetch && git checkout dev
Working Commands工作命令
1) git fetch origin 'remote_branch':'local_branch_name'
2) git switch 'local_branch_name'
3) git pull origin 'remote_branch':'local_branch_name'
The first one is for fetching the branch and creating a local branch from a remote branch第一个用于获取分支并从远程分支创建本地分支
The second one is for switching to the local branch第二个是切换到本地分支
Third for pulling the latest changes of remote to the local branch.第三个用于将远程的最新更改拉到本地分支。
在您的情况下,您可以使用此 cmd。
git checkout -b test origin/test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.