Git Assessment. Can't add .gitignore file to the staging area

Hi,
After I created the .gitignore file I tried to add it to the staging area but received the following error (see below). Also, when I open my Visual Studio Code the Git-repo-management directory doesn’t have .gitignore file that I created through terminal.
Please, help!

Changes to be committed:
(use “git rm --cached …” to unstage)
new file: .DS_Store
new file: images/joseph-roulin.jpg
new file: images/lands-end.jpg
new file: images/pearblossom-hwy.jpg
new file: images/specimens.jpg
new file: images/stag-beetle.jpg
new file: site.html

Untracked files:
(use “git add …” to include in what will be committed)
.gitignore/

elenachernov@Elenas-MBP git-repo-management % git add .gitignore/
error: ‘.gitignore/’ does not have a commit checked out
fatal: adding files failed
elenachernov@Elenas-MBP git-repo-management %

Hi, @Zelda! Welcome to the community! :wave:

It looks like you’re adding a .gitignore/ directory. Notice that / (forward-slash) on the end of your command. What you’re wanting is a .gitignore file (no forward-slash).

You also want to check to make sure that you haven’t accidentally created a .gitignore/ folder instead of a .gitignore file. You should be able to check this by doing ls -al from the terminal.

Hopefully that helps you out?

Thanks, @bryanray!
You were right, I created a directory instead of a file. After I removed it and created the .gitignore file instead I was able to add it to the stage area and to commit later. However, I still don’t see .gitignore file in the Git-repo-management directory at VSC where I suppose to add .DS_Store.
When I run ls -al I see .DS_Store among the files, but how do I make sure it’s among the files to ignore?
Thanks!

Trying to understand a bit more, so I apologize for the questions, but …

Are you saying that when you open your git-repo-management directory, in Visual Studio Code, you don’t see a .gitignore file in the File Explorer on the side?

You’ll almost always see that file from the Terminal. It’s a Mac system file that just exists to maintain some Mac file system details. The goal of “ignoring” it is to make sure that it never gets added into the git repository.

Hopefully that makes sense.

Recommendation

What I would recommend is that you start over fresh. Create a brand new git-repo-management directory and unzip the assessment skeleton into it and start fresh. One of the very first things you should do is to create that .gitignore file and add in the .DS_Store file into it.

Doing that will ensure that the .DS_Store file never gets added into git. You’ll still see the file on your Mac file system, but git will just pretend it doesn’t exist.

Thank you! I followed your recommendation and started over again. Now it makes sense that .Ds_Store should be added to .gitignore before initialiazing git.

1 Like