Reputation: 1087
I am very new to git and its command. Here in my case client already created a branch and ask me to work on the same branch ,Then the following command I triggered.
dev@PGIVM01:~/repository/anp-air$ git checkout 0012.6_cmip_pga
error: pathspec '0012.6_cmip_pga' did not match any file(s) known to git.
Then I tried git branch -a and git branch -r in both cases I can't find the remote branch name 0012.6_cmip_pga .
Then I tried the fetch command git fetch --all
git fetch -r
This time the branch name they specified listed. I have a doubt like how git branch -r missed the branch name first? What is the actual purpose of the fetch command. Help me
Upvotes: 2
Views: 7138
Reputation: 7672
Everything on Git happens locally, on your local repository. When your repository is linked to a remote
repo, there are only two operations that you use to communicate with your remote:
git fetch
- Asks for a delta from all commits, branches, tags and whatsoever that your remote has and you don't, and updates the local references on your local repository.
git push
- Sends out a delta from all commits from a given local branch, that you have and your remote doesn't.
The git branch
command you issued is resolved locally (it won't actively talk to your remote), that's why didn't indicate the remote branch without you actually fetching it first.
Upvotes: 3
Reputation: 24176
By git fetch
command your local history is updated with the remote history ( like branches, commits, tags, etc.) but not merged with local your working tree.
So, after git fetch -all
, git branch -r
or git checkout <branch-name>
is working.
Upvotes: 0