1

I had cloned my git repo and everything looks fine there but now I have created a new branch in GIT repo and now I'm trying to checkout new branch(git checkout -f origin/NewChanges_Wix) getting below error. error: pathspec 'origin/NewChanges_Wix' did not match any file(s) known to git.

Please let me know if I need to do anything before checking out new branch.

Mayank Tripathi
  • 809
  • 1
  • 7
  • 11

2 Answers2

1

First, use git switch (Git 2.23+), not the confusing git checkout command, which deals both with branch names and file paths.

Second, you don't switch to an "origin/xxx" branch: that is a remote tracking branch.

You create/switch to a local branch (which can track automatically the same name if it exists on the remote side.

So if NewChanges_Wix does exists on the remote side (for example GitHub), then:

git fetch
git branch -avv
git switch -c NewChanges_Wix

But if the new branch was created locally, a simple git switch NewChanges_Wix is enough.
You will have, later, to push it: git push -u origin NewChanges_Wix.
Then and only then will you see an origin/NewChanges_Wix when listing your branches (local and remote) with git branch -avv

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Any time something new is created on your remote, you have to

git fetch

This way, your local will fetch all the new changes that have happened on remote, including any new branches. Without it, your local will not know the remote branch exists. You can then simply

git checkout [branch name]

You will not need the origin/ prefix. Git will automatically try to get it from the origin if it doesn't exist locally.

vanamerongen
  • 837
  • 3
  • 11
  • 27