Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 497
Asim K T Avatar asked Jun 09 '16 11:06

Asim K T


People also ask

Can a branch name have '/' in git?

Git imposes the following rules on how references are named: They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence . lock . They must contain at least one / .

How do I checkout a remote branch with a different name?

To be precise, renaming a remote branch is not direct – you have to delete the old remote branch name and then push a new branch name to the repo. Step 2: Reset the upstream branch to the name of your new local branch by running git push origin -u new-branch-name .


1 Answers

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
like image 80
ferranrigual Avatar answered Sep 24 '22 02:09

ferranrigual