Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: have different .gitignore file for each remote

I have a remote repo in which I want to commit certain files (the compiled files to deploy them on a cloud computing platform), but I don't want to deploy them on github...

is there some way to have to different .gitignore files, one for each remote?

like image 261
opensas Avatar asked May 06 '12 23:05

opensas


People also ask

Can a git repo have multiple Gitignore files?

gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple . gitignore files.

Is Gitignore specific to a branch?

Unfortunately, git doesn't support branch-specific . gitignore files or directives. Using different .


1 Answers

This doesn't really make sense in git's model. Commits contain sets of files; all .gitignore files do is tell the UI not to automatically add files matching certain patterns. What this would effectively mean is to have parallel sets of commits that are almost the same, but containing only a subset of the files.

It'd be possible to do this with a branching scheme, where you have a "deployment" branch that splits off of master and is the same but contains the additional compiled files. This could even be automated with git hooks to automatically compile the files and add them to the repo. I'm envisioning a structure like this:

master:       A ---> B ---> C ---> D                \      \      \      \                 \      \      \      \ deployment:      -> A'  -> B'  -> C'  -> D' 

i.e. every time a certain server gets a new commit on master, it builds the project, adds the built files to a new commit from D, and commits that to the deployment branch -- which then doesn't have to be pushed to github.

like image 79
Danica Avatar answered Sep 21 '22 08:09

Danica