Git: there are different .gitignore files for each remote

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

Is there a way to have different .gitignore files, one for each remote?

+50
git github gitignore
May 6 '12 at 23:49
source share
4 answers

This does not make sense in the git model. Commits contains many files; all .gitignore files indicate that the user interface will not automatically add files matching specific patterns. What this actually means is to have parallel sets of commits that are almost the same but contain only a subset of files.

You could do this using a branching scheme, where you have a β€œdeploy” branch that is separate from the main one and is the same, but contains additional compiled files. It can even be automated with git hooks to automatically compile files and add them to the repo. I assume this structure:

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

i.e. every time a certain server receives a new commit on master, it creates a project, adds embedded files to the new commit from D and commits it to the deployment branch, which then should not be clicked on github.

+32
May 07, '12 at 0:00
source share

I will figure out how to do it.

In my case, I needed to synchronize the project with heroku and github (as a public repo).

But some files with personal information were not of interest for sharing in a public repository

Usually a simple project has the following folder structure

 Project folder (remote heroku) - .git - .gitignore - (folders and files) 

What I did was add another level, and in it create another git repository, with gitignore, which would omit some files from my project.

 Project public (remote github) - .git - .gitignore - Project folder (remote heroku) - .git - .gitignore - (folders and files) 

So this is not a git repository with two remote repositories with different gitignores.

There are two different repositories.

In the innermost part, I exclude only the files generated by the IDE and some files created at runtime.

At the most external level, I exclude all files that cannot be published.

+2
Apr 25 '17 at 20:28
source share

Another option is git submodules .

This can be useful if, for example, you want your code and documentation to be in two different repositories with independent access control, etc. Thus, you would have 3 general repos, a submodule repository for documents, another for code, and a "master" (not a git submodule) containing both (to load pypi, possibly). This is a decent way to organize a CS textbook project. Both projects can be successfully launched independently of each other and synchronize them with major releases, guided by a leading repo developer.

+1
Oct 26 '16 at 20:41
source share

Automatic solution for the methods mentioned here:

  • Configure the .git root to ignore the subfolder (s) that you want to transfer differently.
  • Initialize new git in subfolder (s) and assign remote configuration
  • Change the root folder .git / hooks / pre-push file for exec git click in these subfolders based on the input arguments.
+1
May 02 '17 at 3:48 a.m.
source share



All Articles