0

How can I select the files that should never be pulled to the repository?

In particular I want this file myBackend/src/main/resources/application.properties to be never synchronized because each user put local settings on top of a template application.properties stored in the develop branch.

Your branch is up-to-date with 'origin/develop'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   README.md
    modified:   myBackend/docker-compose.yml
    modified:   myBackend/src/main/resources/application.properties

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

    myBackend/udo systemctl start docker

no changes added to commit (use "git add" and/or "git commit -a")

Also, I have some strange untracked files myBackend/udo systemctl start docker. Indeed this is not the file. It was a command written by mistake udo instead of sudo.

How can I remove it?

Markus
  • 3,562
  • 12
  • 48
  • 85
  • You can use a [`.gitignore`](https://git-scm.com/docs/gitignore) file to ignore certain files. [`git clean`](https://git-scm.com/docs/git-clean) removes untracked files from your workspace. – kowsky Sep 05 '18 at 08:01
  • @kowsky: `fatal: clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean` – Markus Sep 05 '18 at 08:11

1 Answers1

2

To remove local untracked files, git clean is your go to guy.

First run:

git clean -n      //This will display the untracked files that will be removed

Then run:

git clean -f      //To remove the file(s) - Note: Remove here means Delete

If it's a directory, do this instead:

git clean -fd

Lastly, to ignore file(s), simply add them to your .gitignore file

So, in your case,

Add myBackend/src/main/resources/application.properties to your .gitignore file.
Chukwuemeka Inya
  • 2,575
  • 1
  • 17
  • 23
  • I would like to add that it is a good idea to add a `application.properties.example` or something file to the repository. This file shoud be filled with some default values (which do not need to be proper values, like example.invalid for a domain) so it is easier for other users to recreate the properties file – Markus Mauksch Sep 05 '18 at 10:36