AEM as Cloud Service: Working with Multiple Source GIT Repositories

Varun Mitra
5 min readMar 15, 2021

AEM as a Cloud Services, requires customers to host their code in a GIT repository. Instead of directly working with Cloud Manager’s Git repository, customers can work with their own Git repository or multiple own Git repositories.

In this blog post, we will cover the process of merging multiple Git repositories and projects into a single Git repository. For simplicity, we will use aem-guides-wknd and aem-guides-wknd-spa projects.

This blog post is comprised of three parts:

| Serial |                Scenario               |  Complexity |
|--------|---------------------------------------|-------------|
| 1 | Clone and Format WKND Project | Medium |
| 2 | Clone and Format WKND-Events Project | Low |
| 3 | Merge WKND and WKND-Events Project | High |

Pre-requisites

  1. github.com account
  2. git command line or GitHub Desktop
  3. Cloud Ready Adobe Experience Manager
  4. Apache Maven (3.3.9 or newer)
  5. Adobe Public Maven Repository in maven settings.xml

Scenario 1a: Clone the WKND Project

  1. Clone WKND Sites Project
git clone --branch master https://github.com/adobe/aem-guides-wknd.git

2. Set up an empty Git Repository

This GIT repository will be referred to as Origin

3. Open the Command Prompt or the Terminal Window.

4. Navigate using the command line to the local directory that contains cloned WKND Project

5. Execute the following commands, to delete the .git folder

  • Windows: rmdir .git /S
  • Mac: rm -R .git

6. Initialize the local repository and point it to the remote Origin GitHub

git initgit add .git commit -m 1_commitgit remote add origin <http URL for the origin git>e.g. git remote add origin https://github.com/varunmitra/aem-guides-wknd.git git push -f origin master

Scenario 1b: Format the WKND project

  1. Navigate using command line to the local directory that contains cloned WKND Project.
  2. Create a new directory.

mkdir wknd

3. Move projects and files inside the newly created directory

git mv pom.xml all core it.tests ui.apps.structure ui.apps ui.config ui.content.sample ui.content ui.frontend ui.tests wknd

4. Resulting folder structure will look like:

5. Create a new pom.xml file.

6. Update the pom.xml file with the following code.

7. Add pom.xml to the current project by running: git add pom.xml

8. Update the pom.xml file for the dispatcher module with the following code.

9. Update pom.xml for the wknd module by removing <module>dispatcher</module>

10. Test project sanity by running mvn verify

11. Commit the GIT Changes: git commit -m “moving wknd”

12. Push the latest changes to Remote Origin GitHub: git push -f origin main

13. Resulting GitHub will look something like:

Scenario 2a: Clone aem-guides-wknd-spa

  1. Clone aem-guides-wknd-spa.

git clone --branch React/latest https://github.com/adobe/aem-guides-wknd-spa.git

2. Set up an empty Git Repository. This GIT repository will be referred to as Origin.

3. Open Command Prompt or Terminal Window.

4. Navigate using command line to the local directory that contains cloned WKND-SPA Project.

5. Execute the following commands, to delete the .git folder:

  • Windows: rmdir .git /S
  • Mac: rm -R .git

6. Initialize the local repository and point it to remote Origin GitHub

git initgit add .git commitgit branch -M maingit remote add origin <http URL for the origin git>e.g. git remote add origin https://github.com/varunmitra/aem-guides-wknd-spa.gitgit push -u origin main

Scenario 2b: Format WKND-SPA project

  1. Navigate using command line to the local directory that contains cloned WKND Project
  2. Create a new directory: mkdir wknd-spa
  3. Move projects and files inside the newly created directory: git mv pom.xml all core it.tests ui.apps ui.apps.structure ui.content ui.frontend wknd-spa
  4. Move the dispatcher folder to a new location for safe keeping. Since, you can only have one dispatcher configuration per project as such we will have to manually merge these with the dispatcher configuration under wknd project.
  5. Create a new pom.xml file.
  6. Update pom.xml with the following code.
  7. Add pom.xml to the current project: git add pom.xml
  8. Test project sanity by running mvn verify
  9. Commit the git changes: git commit -m “moving wknd-spa”
  10. Resulting GitHub will look something like:

Scenario 3: Merge the WKND and WKND SPA project

Description

In this section we will merge the WKND and WKND-SPA Project. In order to achieve this we will follow the given steps:

  1. Add WKND-SPA GitHub as a remote repository for WKND. This will allow us to fetch the content of WKND-SPA Project and add it as a branch of WKND.
  2. Fetch WKND-SPA Project.
  3. Switch the branch pointer to WKND-SPA/Main branch.
  4. Verify the project contents.
  5. Switch the branch pointer back to the WKND Main branch.
  6. Perform a branch merge using — allow-unrelated-histories flag.
  7. Fix the Merge errors. Most importantly, modify the pom.xml to point to both wknd and wknd-spa projects.
  8. Merge and consolidate dispatcher configurations. Ensure to run dispatcher validator before committing any changes
  9. Commit the changes.
  10. Verify the project using mvn verify or mvn clean install
  11. Push the consolidated project to Cloud Manager GitHub.

Exact Steps and Git Commands are as below:

  1. Navigate using command line to the WKND project
  2. Run the following commands:
git checkout maingit remote add wknd-spa <path to cloned WKND-Events Git repository>
e.g. git remote add wknd-spa https://github.com/varunmitra/aem-guides-wknd-spa.git
git fetch wknd-spagit checkout -b wknd-spa wknd-spa/maingit checkout maingit merge wknd-spa --allow-unrelated-histories

3. Fix the Merge errors. pom.xml should look something like:

4. Verify the directory structure, it should look something like:

5. Run mvn verify

6. Commit final changes to the git: git commit -am “updating parent pom”

7. Add cloud manager GitHub: git remote add cm_repo <path to cloud manager git repository>

8. Push to Cloud Manager GitHub: git push -u cm_repo main:merge

--

--