Asim K T
Asim K T

Reputation: 18144

GIT - checkout to branch name starts with '<' symbol

I've created a branch named <title>-changes by:

git checkout -b <title>-changes and did a commit on that branch. Later I checkout to another-branch started working on another-branch. Now I want to checkout to the previous branch (<title>-changes) but I can't do that now through:

git checkout <title>-changes

I know this is a simple issue but can't crack. I tried:

git checkout \<title>-changes
git checkout /<title>-changes
git checkout '<title>-changes'

but no luck. Getting errors like:

$error: pathspec '<title' did not match any file(s) known to git.
$bash: title: No such file or directory
$error: pathspec '<title>-change-pdp ' did not match any file(s) known to git.

Upvotes: 5

Views: 5873

Answers (2)

ferranrigual
ferranrigual

Reputation: 329

You have to escape both < and > because bash treats them as special symbols.

In order to do that, prepend the backward slash \ to each of them:

git checkout \<title\>-changes

This is what I did to test this, and it worked.

mkdir test
cd test/
git init
git branch \<title\>-changes
touch empty
git add empty
git commit -m "Added empty file"
git branch \<title\>-changes
git checkout \<title\>-changes
touch second
git add second
git commit -m "Added second empty file"
git checkout -b another-branch
touch third
git add third
git commit -m "Added third empty file"
git checkout \<title\>-changes

Upvotes: 5

Asim K T
Asim K T

Reputation: 18144

Apart from @Ferran Rigual's answer there is another solution. Like @Matthieu Moy said I had an extra space in the branch name. Removing it solved it too.ie,

I changed git checkout '<title>-changes ' to git checkout '<title>-changes'

And for the record: git checkout '<title>-changes' -- worked too. But I don't know -- has any importance in the command since removal of it doesn't make any difference.

Upvotes: 0

Related Questions