8

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?

Tim
  • 1
  • 141
  • 372
  • 590
  • What is the end goal that you are trying to accomplish? There is probably a better solution than trying to juggle multiple .gitignore files. – GrandOpener Dec 27 '15 at 21:44

2 Answers2

4

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.

Community
  • 1
  • 1
h0m3
  • 104
  • 9
  • thanks. I learned that different directory in the working directory can have different `.gitignore` files. But when you say "add the ignored files to a specific branch", do you mean adding different ignored files to the same `.gitignore` file as the one before switching to a different branch, or do you mean add different ignored files to different `.gitignore` files under different directories in the working directory? – Tim Dec 27 '15 at 21:56
1

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

Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27