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?
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.
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 .
gitignore applies to files in the folder that the . gitignore file is in; it does not matter which branch you currently have selected.
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.
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.
.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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With