4

Repository 1 (R1) is public and contains Ansible roles (if you don't know Ansible, it's fine, it basically contains code).

Repository 2 (R2) is private and contains Ansible playbooks (if you don't know Ansible, playbooks are basically combinations of the roles from R1 to do something).

Right now, R2 (private) has R1 (public) as a submodule. However, I need to be able to create branches on R2 (private) that are, essentially, feature branches. The problem is that the code changes actually need to take place on R1 (public), but I can't branch R1 (public).

Can I make R2 (private) a fork of R1 (public) and then use pull requests to merge changes back into R1 (public)? Is there a better approach I'm not considering?

Ryan O.
  • 310
  • 2
  • 6

1 Answers1

1

You can :

  1. fork R1 (to R1fork)
  2. add the feature(s) you need in R1fork
  3. open a PR on R1 to ask for the integration of your additions in R1fork
  4. in R2, use R1fork as the remote for your submodule
  5. if the PR gets accepted : you can switch back to R1 as a remote

For step 4. :

Starting from git 2.25 (Q1 2020), git submodule has gained the set-url command (see this VonC's answer) :

git submodule set-url [--] <path> <newurl>

If for some reason you can't update the git you use, on older version of git, you will have to edit the .gitmodules file (see for example these two answers by Pavan Sokke Nagaraj and Jim Puls) :

# edit your .gitmodules file : set correct 'url = ...' and 'branch = ...' to
#    R1fork's url and the target branch you wish to include

# then run 'sync' and 'update' :
git submodule sync --recursive
git submodule update --remote --recursive
LeGEC
  • 46,477
  • 5
  • 57
  • 104