0

After switching to a new Mac (macOS Sierra) and re-cloning all of my GitHub repositories, I began to encounter a new problem. Whenever I make changes and save an R script, and run:

git status

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

.DS_Store and .Rhistory appear.

Question: Is there a way to stop and/or ignore (e.g. via .gitignore, see below) these files when committing R scripts to GitHub?

I understand similar questions may have been asked, I decided to still raise this question because I really want to make sure that I get the setting right at the first place, especially if others have encountered similar problems before. If you have a way and/or references of how to solve this highly specific problem--which may require a combination of bash Terminal, R, as well as the operating system

David C.
  • 1,974
  • 2
  • 19
  • 29

2 Answers2

1

I have found several relevant references that can lead to a potential solution:

  1. Mac OS X v10.4 and later: How to prevent .DS_Store file creation over network connections, which simply asks user to run the line below in Terminal to stop generating .DS_Store files:

    defaults write com.apple.desktopservices DSDontWriteNetworkStores true

  2. r - Disabling saving history. This earlier post provides instruction on how to disable creation of .Rhistory files on Windows.

  3. Remove .DS_Store files from a Git repository using .gitignore. I suppose the same could be done to .Rhistory

Still, if you have a better solution, please share with the community!

Community
  • 1
  • 1
David C.
  • 1,974
  • 2
  • 19
  • 29
1

The fastest and simplest way is to add .DS_Store and .Rhistory to your global gitignore file.

Here is how to do it, in a nutshell: open or create (if doesn't exist yet) ~/.gitignore_global and add .DS_Store and .Rhistory on two new lines.

If your repository already includes any unwanted files, use git rm to get rid of them (link).

Maurizio
  • 547
  • 5
  • 13