Reputation: 4842
I am trying to push changes to my repository:
-My Folder
--Chapter 1
--Chapter 2
--Chapter 10
--my_new_file.py
I added new folder Data
a long with changing the code in my_new_file.py
:
-My Folder
--Chapter 1
--Chapter 2
--Chapter 10
--my_new_file.py
--Data
I tried this:
git rm -r --cached Data
git commit -m "Removed folder from repository"
git push origin master
But I get this:
fatal: pathspec 'Data' did not match any files
As I understand from this answer it's the correct way to do it, what am I doing wrong? I want the folder Data
to stay in my local folder but not be pushed to my repository.
Upvotes: 0
Views: 2255
Reputation: 51850
In order for git to be aware that something lies in Data/
, you would first need to stage the folder, and create a commit.
If you haven't done so (it looks like you didn't), no file in Data/
is tracked, and you can push straight away without running git rm --cached
.
You can take one extra step to make sure that Data/
doesn't accidentally land in your repository : you can edit your .gitignore
file and add /Data
to it.
That way : git status
will stop listing Data
altogether, and you won't be able to add those files in future commits (not without an explicit action at least).
Upvotes: 1
Reputation: 535119
The way Git works is that you form a commit in two stages:
First you tell the index (also called the cache or the staging area) that you want this file to be taken account of in the next commit. Do that with every such file.
Second you say "form that commit" based on what the index was told to do.
And the only things that get pushed (or fetched or pulled or whatever) are commits.
So if you never added any of the files in Data to the index (with git add
), then they won't go into the next commit, so they won't get pushed, so you're fine. Git may know (and tell you, when you say git status
) that Data exists, but if it doesn't say (when you say git status
) that files in Data are staged to be committed, then they are not.
Another way to know what's in the index is to say git ls-files --cache
. If you don't see any Data files listed, then when you form the next commit, it won't contain any Data files.
Upvotes: 1