[英]Can't checkout a new branch from remote
我這樣做:
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]$
在首次提交之前,您不能創建多個分支(如果考慮的話,這很有意義)。 在創建從初始分支(已選擇要提交到的分支)的其他分支之前,您需要簽出到該分支並對該分支進行提交。
[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
如您所見,在進行初始提交之后,您可以創建從master
分支分支出來的分支。
注意:這是基於您尚未向存儲庫提交任何內容的假設。 如果您還沒有,請通知我,我將編輯/刪除答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.