I was working on a project and made a local git repository. I did the following series of commands:
$ git init $ git add . $ git commit -m "Initial Commit"
Pretty straightforward, isn’t it? The above initializes the git in the current directory, staged everything in it and committed having the comment “Initial Commit”.
Well, I didn’t realize that there were folders that contains large files such as the setup dependencies that’s about 70-100 MB in sizes. That’s pretty huge if I’m going to deploy my local repository to a remote one.
I then created the .gitignore file and added the directory to be ignored there.
Since I already added the files/directories in git before I add the directory to .gitignore, git will keep tracking it. I don’t want to revert everything back, so I did a “git rm” to remove it first. I also added the “–cached” option to unstage and remove paths only from the index.
After running the following command:
$ git rm --cached Setup
I got this error “fatal: not removing ‘Setup’ recursively without -r”
That’s because I am trying to remove a directory having sub directories and files in it. So I updated my command like:
$ git rm --cached -r Setup
And yay! it worked like a charm.