0

I have my Git bash home directory under version control. I'm using a whitelist (ignore everything except ...):

$ cat .gitignore
# Ignore all the things
*

# But not these (with exceptions)
!*.bash_aliases
!*.bash_profile
!*.bashrc
!*.drush/
!*.drush/*
.drush/cache
!.gitconfig
!.gitignore
!.gitalias
!*.minttyrc
!*.vim/
!*.vim/*
.vim/.netrwhist
!*.vimrc

I want to add the .ssh/config to the exceptions, but I haven't seemed to have gotten the syntax correct.

$ ls .ssh/config
.ssh/config

I have this line in my .gitignore:

$ git diff
diff --git a/.gitignore b/.gitignore
index 22b3a79..b84bcd3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@
 !.gitignore
 !.gitalias
 !*.minttyrc
+!.ssh/config
 !*.vim/
 !*.vim/*
 .vim/.netrwhist

However it hasn't been unignored:

~ (master)
$ git status
Changes not staged for commit:

        modified:   .gitignore

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

Looking at syntax of other things in the .gitignore, I tried this:

$ git diff
diff --git a/.gitignore b/.gitignore
index 22b3a79..659d7be 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@
 !.gitignore
 !.gitalias
 !*.minttyrc
+!*.ssh/config
 !*.vim/
 !*.vim/*
 .vim/.netrwhist

to no avail:

$ git status
Changes not staged for commit:

        modified:   .gitignore

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

What is the syntax to add .ssh/config as an exception in .gitignore?

user151841
  • 17,377
  • 29
  • 109
  • 171
  • Possible duplicate of [.gitignore exclude folder but include specific subfolder](https://stackoverflow.com/questions/5533050/gitignore-exclude-folder-but-include-specific-subfolder) – phd Jul 25 '17 at 15:55

2 Answers2

1

git help ignore:

It is not possible to re-include a file if a parent directory of that file is excluded.

So try add:

!.ssh/
jingx
  • 3,698
  • 3
  • 24
  • 40
0

Going off of jingx's answer, I added these lines:

!*.ssh/
!*.ssh/config

And it seems to have worked:

$ git add .gitignore

$ git status
Changes to be committed:

        modified:   .gitignore
        new file:   .ssh/config

$ git add .ssh/known_hosts
The following paths are ignored by one of your .gitignore files:
.ssh/known_hosts
Use -f if you really want to add them.
user151841
  • 17,377
  • 29
  • 109
  • 171