0

I have two repositories. In the first, I have application code and a .gitignore containing the pattern: dist. I need to push that dist folder to the master branch of the second repository.

Currently, I remove dist from the .gitignore, delete the master branch of the second repository and git subtree push to a new master branch of second repository.

Can I do this any other way?

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
Smbat Poghosyan
  • 719
  • 7
  • 20
  • git does not work this way. .gitignore can only be used for 'untracked' files. So, if you added your directory to the .gitignore before you committed files in it, you cannot push them to any place. On the other hand if you added them to the .gitigore after the fact, it does not matter any longer, git cannot ignore them. So, you are missing some details, i think. looks like you just need separate branches for development and release. You can always push a single branch. – Serge Nov 05 '19 at 11:42
  • I need to do it in this way as I describe, I can't do it another way – Smbat Poghosyan Nov 05 '19 at 11:55
  • Try to describe what you need and your flow in more details in your question. Currently it sounds like you are trying to use git in a non-version-controlled way in respect to the 'distr'. It does not make much sense. – Serge Nov 05 '19 at 13:18
  • What's in `dist`? How are those files created? Why do you ignore it in the first repository? Why are they going into a second repository if they're not supposed to stay in the first? – Anthony Mastrean Feb 21 '20 at 20:59

2 Answers2

0

You can't ignore the folders/files in a repository and then hope to use something like Git subtree to push them to another remote. The subtree command works only with tracked files and commits.

It sounds like your dist directory is the output of your build pipeline and that you need a place to store artifacts.

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
0

I would do it this way:

  1. remove dist folder, remove dist in .gitignore
  2. add a submodule from 2nd repo (the repo contain dist) to dist folder of 1st repo

that way, when you compile the code to production (aka generate files in dist folder), the main repo don't have any changes, but the submodule repo (the second repo) will have changes, and you could treat dist folder as a separated repo

Hunter Tran
  • 13,257
  • 2
  • 14
  • 23