Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different `.gitignore` for different remote repositories?

Tags:

git

I want to ignore different files when pusshing from my local repository to different remote repositories. But there is only one .gitignore file in my local repository. What should I do?

like image 976
Tim Avatar asked Dec 27 '15 21:12

Tim


People also ask

Can you have more than one Gitignore?

Git ignore rules are usually defined in a .gitignore file at the root of your repository. However, you can choose to define multiple .gitignore files in different directories in your repository.

Do I need Gitignore in each folder?

A . 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 .

Does Gitignore apply to all branches?

gitignore applies to files in the folder that the . gitignore file is in; it does not matter which branch you currently have selected.

Should .gitignore be added to repository?

Normally yes, . gitignore is useful for everyone who wants to work with the repository. On occasion you'll want to ignore more private things (maybe you often create LOG or something. In those cases you probably don't want to force that on anyone else.


2 Answers

I think that branching is the best option in your case. Then you can just add the ignored files to a specific branch and upload that branch to the specific repository.

Although git is not mean to be used like that, since .gitignore is just a list of patterns to be ignored in the current branch, tecnically, shouldn't be different .gitignores in the same branch.

Here is a similar situation to yours and how branching can solve this problem.

like image 91
h0m3 Avatar answered Oct 21 '22 05:10

h0m3


.gitignore is effective only against the working directory, thus will not be applicable after a commit has been made. And you cannot push the same history differently to different remotes. So the answer is no, you can't unless you follow the advice of @h0m3 and use different branches (thus split the history).

like image 23
Mykola Gurov Avatar answered Oct 21 '22 06:10

Mykola Gurov