exclude file in Git Template directory does not work

104 Views Asked by At

I am trying to exclude all text documents in my dummy repo as what my textbook suggested. Using my desktop's GUI (and not the terminal), I copied and pasted the exclude file from the git-core git-core/templates/info into my own template file.

I then did echo "*.txt" > exclude

After that, I then ran this command git config --global init.templatedir C:/Users/youse/Documents/"Web Development" /learning_git/.git_template

As you can see, I made sure the path was absolute.

I then did git init and made a txt file in the repo, yet it still allows me to do git add. What did I do wrong here? There was a stackoverflow inquiry regarding this, and it talked about .gitignore. Forgive me, but I don't see a .gitignore

If anyone has an explanation, I would be very grateful.

On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        txt2.txt

nothing added to commit but untracked files present (use "git add" to track)

2

There are 2 best solutions below

0
phd On BEST ANSWER

The file .git/info/exclude must contain just *.txt (*.txt^M$ in cat -Et output) — no quotes, no spaces.

Now you need to fix your template repository and all repositories already created from the template. Manually, alas!

3
yoav lax On

When initialing your git repository you should have done it using:

git init --template= ..\template-location

https://git-scm.com/docs/git-init

Then you would have created it using the template you created earlier.

In addition, You can also create .gitignore file and add any file extension you want, the exact same way like you did which will be used specifically for your repository. Push to the repository to share with all contributors. Note that .gitignore will need to be created manually for every new repo.