0

Here, I'm using a linux terminal. Assume, I have created a new directory

mkdir project_new
cd project_new
git init

And I've created two new files

touch a.txt b.txt

Now I'm staging and committing

git add .
git commit -m 'Add two new files a.txt b.txt'

Creating a .gitignore and made it as a hidden file

touch .gitignore
echo .DS_Store >.gitignore

Now can you help me out in the next steps

how to add both 'a.txt' & 'b.txt' inside the .gitignore to make them as untracked files?

Bhaskar Deori
  • 15
  • 1
  • 8

2 Answers2

1

Since you have already committed your files. They fall into the category of tracked files and are rightfully being tracked by git. You need to remove the files first from the index.

git rm --cached <path-to-files>

Since your a.txt and b.txt are sitting under the root of project, you just need to run,

git rm --cached a.txt b.txt

Add the files to .gitignore as follows,

/a.txt
/b.txt

Commit your changes and then going forward changes to a.txt and b.txt will be ignored by git.

Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47
0

Just for your reference, I always add * into .gitignore to ignore everything, then while I need to add some thing, I use "git add -f". De facto, in most cases, too many temporary files are generated that do not need to be concerned; only in a few cases, some files need to be concerned and added.

zhengfish
  • 113
  • 12