2015-07-16 2 views
6

Я просмотрел другие вопросы по аналогичному вопросу.Как получить всю удаленную ветку, «git fetch -all» не работает

Но они, кажется, говорят, что ответ git fetch --all.

Но в моем случае это не работает.

Это то, что я сделал для этого.

> git branch 
* master 

> git branch -r 
origin/master 
origin/A 

> git fetch --all 
> git branch 
* master  #still not updated 

> git fetch origin/A 
fatal: 'origin/A' does not appear to be a git repository 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists. 

> git fetch remotes/origin/A 
fatal: 'origin/A' does not appear to be a git repository 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists. 

И я также попытался git pull --all также, но результат тот же.

------------------- ------------------- Редактировать

> git pull --all 
Already up-to-date. 

> git branch 
* master    # I think it should show branch A also 

> git remote show origin 
HEAD branch: master 
Remote branches: 
    A  tracked 
    master tracked 

------------------- ------------------- Редактировать

> git pull origin A 
* branch   A  -> FETCH_HEAD 
Already up-to-date. 

> git branch 
* master     # I think it should show barnch A also 
+2

1. Это 'git fetch origin A' не' git fetch origin/A'. 2. 'git pull' будет делать' fetch' и 'merge'. 'git pull -all' должен выполнять тягу по всем ** отслеживанным ** ветвям. – noahnu

+0

Из вашего редактирования, похоже, что он работает. В чем проблема? – noahnu

+0

@noahnu Я думаю, что 'git branch' должен показать' branch A', а также 'master'. – SangminKim

ответ

6

git branch отображает только локальные ветви. git branch -r отобразит удаленные ветви, как вы сами видели.

git branch 
*master 

git branch -r 
origin/master 
origin/A 

git fetch --all будет обновлять список, который вы видите, когда вы вводите git branch -r, но это не будет создавать соответствующие местные отделения.

Что вы хотите сделать, это проверить ветви. Это сделает локальную копию удаленной ветки и настроит восходящий канал на удаленный.

git checkout -b mylocal origin/A 

git branch 
master 
*mylocal 

git branch -r 
origin/master 
origin/A 

mylocal в этом случае origin/A. Параметр -b переключится на новую ветку после ее создания. Вы также можете просто ввести: git checkout A будет автоматически указывать новую ветку.

0

Необходимо также создать выбранную ветку:

git fetch --all && git checkout A 
1

Я думаю, что вы действительно ищете команду git branch -a. Он отобразит все локальные и удаленные филиалы. Вот пример:

# Only show local branches 
$ git branch 
* master 
    develop 

# Only show remote branches 
$ git branch -r 
    origin/HEAD -> origin/master 
    origin/master 
    origin/develop 
    origin/foo 

# Show both local and remote branches 
$ git branch -a 
* master 
    develop 
    remotes/origin/HEAD -> origin/master 
    remotes/origin/master 
    remotes/origin/develop 
    remotes/origin/foo 

Вы заметите, что все ветви есть - команда покажет как локальные, так и удаленные ветви.

foo ветка только выходит на пульт дистанционного управления, у меня нет местного отделения foo. Чтобы создать локальную foo ветку, я хотел бы использовать checkout команду:

# Create a local 'foo' branch from the remote one 
$ git checkout foo 
Branch foo set up to track remote branch foo from origin. 
Switched to a new branch 'foo' 

# Show both local and remote branches 
$ git branch -a 
* foo 
    master 
    develop 
    remotes/origin/HEAD -> origin/master 
    remotes/origin/master 
    remotes/origin/develop 
    remotes/origin/foo 

Это должно объяснить, что вы видите на местном уровне.

Смежные вопросы