Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i include only specific folders in git using .gitignore?

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?

like image 455
fenec Avatar asked Apr 25 '14 19:04

fenec


1 Answers

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

like image 135
nickel715 Avatar answered Oct 19 '22 12:10

nickel715