Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use a .gitignore with a bare repo?

Tags:

git

github

I have a bare repo that I setup using

git init --bare

It also has a simple post-receive hook like this that updates the web application.

git --work-tree=/foo/public_html --git-dir=/foo/root.git checkout -f

I want to also push to github but I did not want to push my entire repo.

git push github_repo

I wanted to use a .gitignore file in the root directory that ignores all my php files:

*.php

Can I do it this way?

like image 856
cade galt Avatar asked Oct 19 '22 00:10

cade galt


2 Answers

I want to also push to github but I did not want to push my entire repo.

git push github_repo

I wanted to use a .gitignore file in the root directory that ignores all my php files:

*.php

Can I do it this way?

No.

Git's ignore system prevents files from being tracked. In other words, ignored files are never added to the repository at all. The ignore system has no effect on tracked files, so by the time the files reach your repository (bare or otherwise) they're no longer ignorable.

Currently the .gitignore in root is ignoring files on my client machine that pushes to the bare repo ( server ).

This works because it prevents the files from being tracked in the first place.

like image 151
Chris Avatar answered Oct 21 '22 15:10

Chris


You could put all your PHP files in a separate git repository.

That way you could use it as a submodule where you need to use the PHP files. And as your bare clone has no submodules, you don't need a specific gitignore.

like image 34
Abizern Avatar answered Oct 21 '22 15:10

Abizern