-1

I am having trouble with my gitignore file.

My directories look like this:

/root
    /.gitignore
    /README.md
    /embedded-programming-periode-3/
        /somefolder/
        /somefiles.txt
        /main.c

And I want to ignore everything except: .gitignore, README.md and main.c

How would I go about this? I tried various things without success.

L Ja
  • 1,384
  • 1
  • 11
  • 22

1 Answers1

0

And I want to ignore everything except: .gitignore, README.md and main.c

A quick look at the documentation of .gitignore shows that it is as easy as:

# ignore everything
/*

# except .gitignore, README.md
!/.gitignore
!/README.md

# excepting main.c is a bit tricky:
# must except its parent directory ...
!/embedded-programming-periode-3/
# ... ignore everything in it ...
/embedded-programming-periode-3/*
# ... except for main.c
!/embedded-programming-periode-3/main.c
axiac
  • 68,258
  • 9
  • 99
  • 134
  • I am new to git, but if I run git status, it should show up as a new file, right? Because that is not the case. – L Ja Feb 04 '18 at 22:51
  • 1
    What says `git status`? – axiac Feb 04 '18 at 22:53
  • https://pastebin.com/DyzH2a1P – L Ja Feb 04 '18 at 22:55
  • Make sure the `.gitignore` file is in the same directory as `README.md` and `embedded-programming-periode-3`. From the output you put on pastebin.com it seems the `.gitignore` file is inside the `embedded-programming-periode-3` directory. – axiac Feb 04 '18 at 23:01
  • The .gitignore is in the root folder of the project, so in the same directory as README.md – L Ja Feb 04 '18 at 23:05
  • I think it looks like that because there is a embedded-programming-periode-3 folder inside embedded-programming-periode-3. With the first one being the root of the project. – L Ja Feb 04 '18 at 23:09
  • It looks like that because it is like that. You added or modified the `.gitignore` file inside the `embedded-programming-periode-3` and that's why it doesn't work as expected. – axiac Feb 04 '18 at 23:21