0

I have a directory:

a
b
c

I did git init to create repistory. But I want my repository to only contain

a
b

No matter what else gets added. Is that the proper workflow?

Kern
  • 87
  • 1
  • 5

2 Answers2

1

Add a .gitignore file to your repo which contains glob style patters of what you do not want to be tracked by git. For example in one of my GO repos I have:

23:10 $ cat .gitignore 
*/**/*.a
*/**/telemetry

In your case it would simply be:

$ cat .gitignore
c

Hope this helps

Wes
  • 6,455
  • 3
  • 22
  • 26
  • so .gitignore can ignore everything that isn't `a` or `b`? – Kern Dec 24 '15 at 07:13
  • Ah, i see the subtlety of your question. You are looking for the logical not operation. The problem is you can say !a and then !b which will give you everything. There is no way to construct !a and !b which is what you really want. Full documentation is here: https://git-scm.com/docs/gitignore – Wes Dec 24 '15 at 07:19
1

If you want to ignore everything except a and b, your .gitignore should contain:

# Ignore everything
*

# But not these files...
!.gitignore
!a
!b

remark that you should add gitigore also to your repository :)

Chris Maes
  • 35,025
  • 12
  • 111
  • 136