0

I am trying to learn Git. I have a Macbook and my instructor is on Windows. I installed Git using Homebrew. When I went to do a test run and create a simple folder on the desktop, with a file in it, to practice initializing Git on it...it worked...except, my MAC ALSO pulled two files which are typically hidden, a .localized file and a .DS_Store file and included them in my VS Code to be tracked. Now I can't figure out how to "untrack" them, and I tried git rm --cached .localized (which as best as I could tell was the name of the file) But this did not work. How do I make sure I am only initializing the files I want?

Thank you sooo much, I do not usually work on the back end and want to learn for GitHub.

Elizabeth
  • 61
  • 1
  • 8
  • Does this answer your question? [Why are there two ways to unstage a file in Git?](https://stackoverflow.com/questions/6919121/why-are-there-two-ways-to-unstage-a-file-in-git) – Gaël J Jun 03 '21 at 16:45
  • Reading this a bit it sounds like I chose the right command, git rm --cached but it did not work with these files unless I have the file names wrong but I typed them as they appeared under git status – Elizabeth Jun 03 '21 at 16:48
  • What does your `git status` says? – Gaël J Jun 03 '21 at 16:50
  • Untracked files: (use "git add ..." to include in what will be committed) .DS_Store .localized – Elizabeth Jun 03 '21 at 16:50
  • On branch master No commits yet Untracked files: (use "git add ..." to include in what will be committed) .DS_Store .localized nothing added to commit but untracked files present (use "git add" to track) – Elizabeth Jun 03 '21 at 16:51
  • Well it says these files are _not_ tracked. Then nothing to do except maybe adding them to `.gitignore` to not be bothered with them in the future. – Gaël J Jun 03 '21 at 16:52
  • I am worried because they may become tracked once I do git add with the other files I DO want to practice tracking on, they just appeared out of nowhere... so if i type .gitignore and the file name? – Elizabeth Jun 03 '21 at 16:54
  • It says .gitignore is not a command I also tried git ignore – Elizabeth Jun 03 '21 at 16:58
  • You have to create a file named `.gitignore` and add the names of the files to ignore in it. There is probably an answer on SO explaining how. – Gaël J Jun 03 '21 at 17:20
  • Documentation on .gitignore file: https://git-scm.com/docs/gitignore. Repository of recommended .gitignore files: https://github.com/github/gitignore – Ali Samji Jun 03 '21 at 17:27

1 Answers1

1

Add a file in your repository with the name .gitignore which has the following contents:

.DS_Store
.localized

The content of this file specifies intentionally untracked files that Git should ignore. You can find more details in the documentation. This will prevent you from unintentionally staging/committing them in the future.

GitHub has a collection of useful templates here. There are some generators online that can be used to create more comprehensive .gitignore files to handle the most common OS, IDEs, frameworks etc. One example is gitignore.io

Matt
  • 12,848
  • 2
  • 31
  • 53