3

I am trying to make sure the contents of the .ssh directory do not get into the Git Repository:

executeS:~$ git diff --stat --cached origin/master

.gitignore           |   7 ------
 .ssh/.gitignore      |   2 ++
 .ssh/authorized_keys |   1 +
 .ssh/id_rsa          |  51 ++++++++++++++++++++++++++++++++++++++
 .ssh/id_rsa.pub      |   1 +
 .ssh/known_hosts     |   2 ++
 .viminfo             | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------

I then take them out as follows:

executeS:~$ git rm --cached .ssh/authorized_keys
rm '.ssh/authorized_keys'
executeS:~$ git rm --cached .ssh/id_rsa
rm '.ssh/id_rsa'
executeS:~$ git rm --cached .ssh/id_rsa.pub
rm '.ssh/id_rsa.pub'
executeS:~$ git rm --cached .ssh/known_hosts

I have the following .gitignore file

executeS:~/.ssh$ pwd
/home/dockcclubdjango/.ssh

executeS:~/.ssh$ cat .gitignore
.*
!/.gitignore

But then if I do, "git add . -A", I get waht I had in step 1 all over again. What can I do to make sure that .ssh NEVER gets into the repository?

1615903
  • 32,635
  • 12
  • 70
  • 99
Casey Harrils
  • 2,793
  • 12
  • 52
  • 93
  • Did you try this: https://stackoverflow.com/a/27629812/2008111 ? – caramba Nov 11 '17 at 14:55
  • I think the `.gitignore` file must been in the root directory... presuming here that your working directory / root is `~`, and the `.gitignore` files is `~/.ssh/.gitignore`. – Attie Nov 11 '17 at 15:04

1 Answers1

5

You need also

  1. add /.ssh line to your .gitignore
  2. commit all changes (removal of .ssh from git and addition of the line to .gitignore)

Now git add -A will not add it back (tested with Git 2.15.0)

Regarding second question ("What can I do to make sure that .ssh NEVER gets into the repository?"): .gitignore does not prevent a file to be added to a repository. You can always add ignored file with git add -f path/to/file.

Piotr Findeisen
  • 19,480
  • 2
  • 52
  • 82