Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git Can';t从远程签出新分支_Git - Fatal编程技术网

Git Can';t从远程签出新分支

Git Can';t从远程签出新分支,git,Git,我这样做: git fetch --all Fetching origin remote: Counting objects: 242, done. ............ From bitbucket.org:xxx/xxx xxxx..xxxx develop -> origin/develop * [new branch] branch1 -> origin/branch1 xxxx..xxxx master -> origin

我这样做:

git fetch --all
Fetching origin
remote: Counting objects: 242, done.
............
From bitbucket.org:xxx/xxx
   xxxx..xxxx  develop    -> origin/develop
 * [new branch]      branch1 -> origin/branch1
   xxxx..xxxx  master     -> origin/master
然后我做了:

git checkout branch1
error: pathspec 'branch1' did not match any file(s) known to git.

但我应该去branch1登记。这是怎么回事?

没有本地分支称为
branch1
。你需要说

git checkout -b branch1 origin/branch1
这将创建一个名为branch1的本地分支,该分支跟踪来自实验的远程分支
branch1

[wei2912@localhost wee-repo]$ git init
Initialized empty Git repository in /home/wei2912/tmp/wee-repo/.git/
[wei2912@localhost wee-repo]$ git checkout -b branch1
Switched to a new branch 'branch1'
[wei2912@localhost wee-repo]$ git checkout -b master
Switched to a new branch 'master'
[wei2912@localhost wee-repo]$ git checkout branch1
error: pathspec 'branch1' did not match any file(s) known to git.
[wei2912@localhost wee-repo]$ git branch -a
[wei2912@localhost wee-repo]$ 
在初始提交之前,不能创建多个分支(如果仔细考虑,这是有道理的)。您需要先签出到某个分支并提交到该分支,然后才能创建从初始分支(您选择提交到的分支)分支出来的其他分支

如您所见,在进行初始提交之后,您可以创建分支,该分支从
master
分支分支分支出来


注意:这是假设您尚未向存储库提交任何内容。如果您没有,请通知我,我将编辑/删除我的答案。

通常,人们不需要这样做。@OliCharlesworth,那么需要什么?接受努法的建议,但选择-tb而不是-b,这将使您的本地分支成为跟踪分支。origin/branch1和remotes/origin/branch1之间有什么区别吗?@DonBranson,默认情况下,它不会跟踪远程/branch1吗?您是否向存储库提交了任何内容?请您将
git branch-a
的输出添加到您的问题中。似乎很明显,OP的repo有多个提交(来自
git fetch的输出——问题中显示的所有
)。
[wei2912@localhost wee-repo]$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
[wei2912@localhost wee-repo]$ touch test.txt
[wei2912@localhost wee-repo]$ git add test.txt
[wei2912@localhost wee-repo]$ git branch -a
* master
[wei2912@localhost wee-repo]$ git checkout -b branch1
Switched to a new branch 'branch1'
[wei2912@localhost wee-repo]$ git branch -a
* branch1
  master