So I've created a new rails app rails new myapp
then then a cd myapp
and then git init
and then git checkout -b experimental
- it created new branch just fine, and as I tried switch back to the master it did not work and I get the error that's in the title, also git branch
- nothing, so I did chceck and the branches folder is empty as I expected?
Your first branch is not created until your first commit is made. If you simply git init
and immediately switch to a new branch, you will not have created a master
branch. For example:
% git init .
% git branch
Shows that you do not have any branches. If you are to switch branches, you will change the branch that will be committed to (and therefore created) when you create your first commit. However you can see that this still does not show as a branch that exists:
% git checkout -b experimental
% git branch
Still shows no branches. However when you create your first commit:
% echo hello > newfile.txt
% git add newfile.txt
% git commit -mexperimental
[experimental (root-commit) dab457a] experimental
1 file changed, 1 insertion(+)
create mode 100644 newfile.txt
Now the experimental
branch exists, though master
does not, since you did not commit to it:
% git branch
* experimental
The error message you received is particularly dense, as you can use git checkout
to either switch to a different branch, or to write a file to the working directory. When you run:
% git checkout master
This is first interpreted as "switch to the master
branch". Lacking a master
branch, however, it is then interpreted as "check out the file master
to the working directory". Since you also lack that, it tells you that it could not find a file (or, really, a pathspec) master
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With