I am currently in some branch and want to checkout to a remote branch named
dev1 which is not yet existent in local git. So I tried calling,
$ git fetch origin dev1 $ git checkout origin dev1
but it gave me an error.
error: pathspec 'BRANCH-NAME' did not match any file(s) known to git
BTW, fetching worked fine and did not complain. So I tried
$ git checkout -b dev1 origin/dev1
but got error:
error “Cannot update paths and switch to branch”
I checked if my local git was tracking remote
dev1 branch by
$ git remote show origin remote origin Fetch URL: firstname.lastname@example.org:someuser/somegit.git Push URL: email@example.com:someuser/somegit-TODAH.git HEAD branch: master Remote branch: dev tracked Local branch configured for 'git pull': dev merges with remote dev Local refs configured for 'git push': dev pushes to dev (up to date)
From the output, we can see local git was not tracking remote
make local git track remote
$ git fetch origin dev1:dev1
this should add tracking remote_branch_name(dev1) to local git by the name of local_branch_name(dev1). Mind the confusion due to use same name in remote and local.
$ git checkout dev1
and goal is achieved.