0

I'm working on a project and I have a certain .jar library that multiple branches use. Rather than copy paste the .jar file into each branch, is there a cleaner way to do that? I tried researching github submodules but I'm not sure if that would work (and it confused me).

  • Does this answer your question? [How to create a new (and empty!) "root" branch?](https://stackoverflow.com/questions/15034390/how-to-create-a-new-and-empty-root-branch) – Mike Slinn Apr 02 '21 at 03:31
  • @Mike Slinn unfortunately it doesn't. I have multiple branches that require the same .jar file to compile and I want to avoid putting the .jar file in all the branches. I'm trying to figure out if there's a way that I can for example make the .jar file its own branch and make the other branches dependent on that branch. – Anonymous12332313 Apr 02 '21 at 17:14
  • Your use case seems to fit exactly what the link I showed you describes. – Mike Slinn Apr 02 '21 at 17:21
  • @Mike Slinn Sorry I'm confused about that post then. To me it seems like the person wants to create a branch that's "independent" of all other branches, a branch that has nothing in it. I'm not sure how that allows me to avoid copy pasting a .jar file into multiples branches. – Anonymous12332313 Apr 02 '21 at 18:14
  • An orphan branch could contain your jar file, and you could rebase its first commit after the initial commit on master. Presumably all your other branches were made later. – Mike Slinn Apr 02 '21 at 18:30
  • A simpler way would be to just commit the jar to HEAD, then rebase that commit to just after the initial commit on master. – Mike Slinn Apr 02 '21 at 18:32
  • This should do what I just described, and I think it does what you want: https://stackoverflow.com/questions/21353584/git-how-do-i-add-a-file-to-the-first-commit-and-rewrite-history-in-the-process – Mike Slinn Apr 02 '21 at 18:44
  • @Mike Slinn Sorry I know you're trying to help but I'm still confused. If I want multiple branches to have access to the same .jar file without copy pasting the file, how does adding it to the first commit do that? Let's say there's three branches, master, branchA, and branchB. If I want both BranchA and BranchB to have access to library.jar without copy pasting it into both, how would adding it to master help? I'm sure I'm missing something I'm just not sure what. – Anonymous12332313 Apr 03 '21 at 02:42
  • If you create branchA on the 10th commit of the master branch, then everything that was in master at that time also appears in branchA. All you have to do is find a simple way to rewrite git history so that your jar file's creation time in history is the second commit, say. That way every branch will see the jar. – Mike Slinn Apr 03 '21 at 02:49
  • @Mike Slinn thank you very much! – Anonymous12332313 Apr 04 '21 at 05:30

0 Answers0