10

I have a file called gradle.properties I want to remove it form tracking file so when I push to GitHub it doesn't update remote repo

  • do you need to ignore gradle.properties file from commits ? can you clarify the problem some more – isuruAb Mar 10 '17 at 17:25
  • The question of which this question is supposedly a duplicate explicitly asks how to do this "temporarily" – a *separate* question for how to do so permanently seems useful (even if *most* of the answers on that other question are effectively answering this one). – Kenny Evitt Jun 21 '19 at 19:17

1 Answers1

24

Add the file to .gitignore file. This makes git ignore it. However, if your file is already tracked then you need to remove it from tracking. This can be done using git rm --cached <file>. Please refer to git documentation for complete description of the process.

user2773289
  • 452
  • 2
  • 6
  • 3
    This is, unfortunately, entirely wrong. Once a file is tracked, its name in `.gitignore` is irrelevant. – torek Mar 10 '17 at 17:46
  • 1
    @torek, you are right, I have updated the answer to address your point. – user2773289 Mar 10 '17 at 18:02
  • @user2773289 I accidentally committed a folder. I ran 'git reset HEAD core/' which moved folder contents to 'Unstaged changes after reset:' list. I ran 'git status' to see files listed as "Changes not staged for commit:" which is good. I added 'core' to .gitignore; ran 'git status', but the files are still appearing in "not staged for commit" list. I tried: 'git rm --cached -r core' but that moved the files BACK into the "Staged for commit list", so I re-ran git reset HEAD core/ to get them back into "not staged..." but how do I get git to untrack/forget/ignore them? – Auxiliary Joel Jul 29 '19 at 01:56
  • But it deletes the file as well. – Avin Shum Jul 28 '21 at 09:57