Really getting stuck on this one. I've googled a lot and can't figure out what I've done wrong...

I'm trying to create a new file, via the git add README.txt command in terminal...

(So far I've created a new folder Fundamentals. Created a sub-folder git-practice. And created a git repo via git init command)

However, when I try and add a file in fundamentals/git-practice, i get the following error..

fatal: pathspec 'README.txt' did not match any files

Not sure what I'm doing wrong.. everything seems to make sense. Here's the code:

Reenas-MBP:~ reenaverma$ cd ~Reenas-MBP:~ reenaverma$ ls72.png GitHub flask-workshopApplications Library fundamentalsCreative Cloud Files Movies funny_thingsDesktop Music get-pip.pyDocuments Pictures worldDownloads Public wwlcDropbox Retrieved ContentsReenas-MBP:~ reenaverma$ cd fundamentalsReenas-MBP:fundamentals reenaverma$ lsgit-practiceReenas-MBP:fundamentals reenaverma$ cd git-practiceReenas-MBP:git-practice reenaverma$ ls -a. .. .gitReenas-MBP:git-practice reenaverma$ pwd/Users/reenaverma/fundamentals/git-practiceReenas-MBP:git-practice reenaverma$ git add README.txtfatal: pathspec 'README.txt' did not match any filesReenas-MBP:git-practice reenaverma$ 
6

Best Answer


I'm trying to create a new file, via the 'git add README.txt' command in terminal...

git add does not create a new file. It adds an existing file to be indexed by git. You'll need to create the file first.

Just type in your terminal (e.g. in git bash):

git >> README.mdgit add README.md

fatal: pathspec 'README.txt' did not match any files

You get this error because there is no file named README.txt in the current directory. Git is in the business of managing files that you create with other programs, usually a text editor or IDE. git add only adds the file to the index. It does not create any files directly. You need to use another tool to do so. Use your favorite text editor (I suggest Notepad++, Sublime Text 3, or Atom) and create a file with some text.

I had the same problem and after typing ls I had git display all the files I had in the folder, then I found that I had saved the readme file as readme.txt.txt. Hence I had to rename the file to readme.txt and then I was able to add it successfully.

I do following this command (windows10) in terminal and everthing is working

  • git initgit add README.txtgit commit -m "first commit"git remote add origin https://github.com/your_github/github_project.git So I create my token in github then git push origin master

The following code works for me

git add README.txt