Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative parent directory path for .gitignore

Tags:

git

In my sbt-project I have some files that I do not want to share with my colleagues as they are personal notes and stuff like that. I want to have them .gitignored. How can I do this. I placed a folder personal into the project and added a .gitignore there with the line

 ../personal/

I hoped that would hide the folder personal (including the responsible .gitignore) from git, but it seems this is not valid for git. How can I achieve this?

Also /personal/ does not work as hoped.

like image 400
Make42 Avatar asked Nov 05 '16 17:11

Make42


2 Answers

Option 1: Using a .gitgnore file

In your personal directory create a .gitignore file with the following content:

*
  • Git will then ignore the personal directory and any files inside it.
  • Ignoring files or directories outside of the personal directory is not possible using this approach (at least I don't know how to achieve this using this option).

Option 2: Using the .git/info/exclude file

Add the following lines to the .git/info/exclude file:

/personal
*.dictionary
  • Git will then ignore the personal directory and any files inside it.
  • It will also ignore all files with a .dictionary suffix no matter if they are inside or outside the personal directory.

Further notes & documentation

  • Files already tracked by Git are not affected. The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked. To stop tracking a file that is currently tracked, use git rm --cached.

  • gitignore man page: See section "Description" to get an overview about the different options which exist to ignore files within a git repository and when to use which option.

like image 172
Christoph Zauner Avatar answered Sep 21 '22 12:09

Christoph Zauner


add a .gitignore file on your project's root directory like below

sbt-project
 |_ app
 |_ personal
 |_ .gitignore

The paths you add on .gitignore to be skipped should be relative to the directory where .gitignore file is located. In this case, add this line to skip all contents of your personal directory inside sbt-project

personal/
like image 22
sa77 Avatar answered Sep 19 '22 12:09

sa77