1

I have just come across a situation where I have added all the files to git hub with git add . command. However there are few files like I do not want to add to git hub like .gitignore which has .vscode .env and nodemodules but the issue is they do keep adding all the time when I perform the git add ..

I tried to perform certain task,

Which is to untrack the file first using

git rm --cached .gitignore

and then

git config --global core.excludesfile .gitignore

but the result is no change.

can anyone help with this, what way it should be done correctly?

Thanks

Tapesh Patel
  • 131
  • 1
  • 17

2 Answers2

1

when you edit anything in the .gitignore file you have to add it to the staging area and commit it first, in order to see the change commit the .gitignore first.

osama
  • 24
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 21 '22 at 19:53
1
git rm -r --cached .
git add -A
git commit -am 'Removing ignored files'

The first command will un-track all files in your git repository.

The second command will then add all of the files in your git repository, except those that match rules in your .gitignore. Thus, we have un-tracked several files with just two commands.

Then the last command is to commit the changes, which will just be removed files.

Re7roVM
  • 24
  • 6