Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git checkout master error: pathspec 'master' did not match any file(s) known to git

Tags:

git

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?

like image 544
Roberto Baggio Avatar asked May 26 '15 13:05

Roberto Baggio


1 Answers

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.

like image 82
Edward Thomson Avatar answered Nov 09 '22 19:11

Edward Thomson