Question

So i would like ignore everything except a file and a specific folder:

rben@ubuntu:~/sites$ ls
development-box  puppet  sites  Vagrantfile  www-cms  www-common  www-mmfa
rben@ubuntu:~/sites$ cat .gitignore
*
!Vagrantfile
!puppet/
rben@ubuntu:~/sites$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       Vagrantfile
nothing added to commit but untracked files present (use "git add" to track)

I am expecting to see puppet in the list of untracked files. How can i include only the directory puppet?

Was it helpful?

Solution

ok nice, try the following gitignore file:

# Ignore everything in repository root 
/*

# Files to not ignore
!/.gitignore
!/some_other_files

# Folder to not ignore
!/puppet/

The key point is the slash before the *.

In your case the * affected also to the files in puppet.

So to be on the safe side use absolute paths like in my example

I asked a similar question a while ago: Git Ignore everything in a directory except subfolders

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top