Using Git in Oracle Developer Cloud Service

Oracle Developer Cloud Service uses Git source control management to save and manage your application source code files.

Tip:

If you are new to Git, read the Git documentation at http://git-scm.com/doc and the Git book at https://git-scm.com/book/en/v2 to learn more about Git and Git basics such as local and remote repositories, commits, SHA-1 checksum hashes, branches, tags, and push and pull branches.

If you have recently created an Oracle Developer Cloud Service project or have joined one, you must first set up the Git repositories of your project.

  • If there is no Git repository in the project, create or import a Git repository. You must be assigned the project Owner role to create or import a Git repository. When you create a repository, you can choose to create an empty repository or initialize it with a readme file, or import files and revisions from an external Git repository.

    To create or import a repository, click the + New Repository button in the Code page, or the Repositories section of the Project page. For information about the fields of the New Repository dialog, see step 4 in Creating a Git Repository in the Project.

    Instead of importing an external remote Git repository to the project, you can also add a link to the remote repository by adding the URL of the remote repository in your project. You can do so from the Administration page and require the project Owner role. For more information about adding the URL of an external remote repository, see Using an External Git Repository.

  • If the project Git repository (also called as the project remote Git repository or the hosted Git repository) is empty, you can perform any of the following actions to upload your files to the repository.

  • If the remote Git repository is populated with the readme file or the application source code files, clone the repository to access and update its files. See Cloning the Oracle Developer Cloud Service Project Git Repository.

Cloning the Oracle Developer Cloud Service Project Git Repository

To add files or access the files of a remote Git repository, you must first clone it to your local computer. You can either use the Git command line interface or the Git integration available in IDEs to clone the remote Git repository.

Using the Git Command Line Interface

If you are comfortable using a command line interface, download and install the Git command line tool. After downloading the command line tool, set up and customize your Git environment. For more information, see Using the Git Command Line Interface.

To clone the remote Git repository:

  1. Open the Git command line interface.

  2. Navigate to the directory where you want to clone the remote Git repository.

  3. Enter the git clone <repository-url> command.

    See Viewing and Copying a Git Repository’s Access URL to get the Git repository’s URL.

    HTTPS example:

    git clone https://john.doe%40oracle.com@developer.us.oraclecloud.com/developer1111-usoracle22222/s/developer1111-usoracle22222_myproject/scm/developer1111-usoracle22222_myproject.git

    SSH example:

    git clone ssh://usoracle22222.john.doe%40oracle.com@developer.us.oraclecloud.com/developer1111-usoracle22222_myproject/developer1111-usoracle22222_myproject.git

    Note:

    If you are using SSH, create an SSH key and add it to Oracle Developer Cloud Service. See Generating an SSH Key.
  4. Enter the password, if required.

The remote Git repository is cloned to your local directory. Open the directory and verify that a .git subdirectory has been created. Do not add or modify files of the .git subdirectory. You can now add or edit the application source code files, create and manage branches, commit them to the cloned Git repository, and then push the updates to the remote Git repository. See Using Git Commands.

If your application is not ready, you may initialize the Git repository with a readme file. Follow the on-screen Git commands to add a readme file to the repository, commit it, and then push the master branch to the remote repository.

After cloning the repository, use the git add command to add new files. Use the git commit command to commit all added and updated files to the local Git repository.

Using Git with Eclipse IDE

Eclipse IDE and OEPE use EGit, an Eclipse Team provider for Git, to access and manage Git repositories.

You can also use the Oracle Cloud view of IDE to clone and manage Git repositories. Using the Oracle Cloud view, you can drag and drop the OEPE project into the specific Git repository and then follow the wizard to commit and push the updates. You can also use the Oracle Cloud view to configure or update the build jobs and push dependencies to the maven repository, track issues, and monitor builds of the project. See Using the Oracle Cloud View and Using Eclipse IDE with Oracle Developer Cloud Service.

To clone a remote Git repository using EGit:

  1. In the IDE, open the Git Repositories view.

    Select Window, then Show View, and then select Git Repositories. If Git Repositories is not visible, click Other. In the Show View window, expand Git and select Git Repositories.

  2. In the Git Repositories view, click Clone a Git Repository.

  3. In the Source Git Repository page of the Clone Git Repository wizard, select Clone URI, and click Next.

    See Viewing and Copying a Git Repository’s Access URL to get the Git repository’s URL.

    If you are using the SSH URL to access the repository, create an SSH key and add it to Oracle Developer Cloud Service.See Generating an SSH Key. Also, in the Remote Repository page, instead of entering the password, select the Private Key File.

  4. In the Clone Git Repository dialog, enter the remote Git repository URL in URI, select the protocol in Protocol, enter the user name in User, and password in Password. Click Next.

  5. In the Branch Selection page, select the branches to clone, and click Next.

    If the remote repository is empty, the Branch Selection page will be empty too. Click Next to continue.

  6. In the Local Destination page, specify the local Git repository directory in Directory, and click Finish.

The cloned repository appears in the Git Repositories view.

If the cloned Git repository contains files, you can import them to an IDE project. To import the files from the cloned Git repository:

  1. Right-click the cloned Git repository and select Import Projects.

  2. In the Select a wizard to use for importing projects page of Import Projects from Git Repository dialog, select the desired project import option and click Next.

  3. In the Import Projects page of the Import Projects from Git Repository dialog, note the project name and directory, and click Finish.

The IDE project opens in the Project Explorer.

For more information about how to add an IDE project to the cloned Git repository, manage branches, commit and push commands, read the EGit documentation at http://wiki.eclipse.org/EGit/User_Guide.

Using Git with NetBeans IDE

NetBeans IDE uses a Git plugin to perform Git tasks in the IDE.

You can also use the NetBeans IDE Oracle Developer Cloud Service Team Server plug-in to clone and manage Git repositories. Using the Team Server plug-in, you can drag and drop the NetBeans IDE project into the specific Git repository and then follow the wizard to commit and push the updates. You can also use the Team Server to track issues, and monitor builds of the project. See Using the Oracle Developer Cloud Service Team Server and Create an Oracle Developer Cloud Service Issue in NetBeans IDE.

To clone a remote Git repository in NetBeans IDE:

  1. In NetBeans IDE, click the Team menu, select Git, and then select Clone.

  2. In the Remote Repository page of the Clone Repository wizard, enter the remote Git repository URL in Repository URL, user name in User, password in Password, and the destination directory of the cloned Git repository in Clone into. Click Next.

    See Viewing and Copying a Git Repository’s Access URL to get the Git repository’s URL.

    If you are using the SSH URL to access the repository, create an SSH key and add it to Oracle Developer Cloud Service. See Generating an SSH Key. Also, in the Remote Repository page, instead of entering the password, select the Private Key File.

  3. Select the branches of the remote repository you want to clone, and click Next.

  4. If you did not specify the destination directory of the cloned repository in Step 1, specify the directory, and click Finish.

For more information about how to add an NetBeans IDE project to the cloned Git repository, manage branches, commit and push commands, read the NetBeans IDE and Git documentation at https://netbeans.org/kb/docs/ide/git.html.

Using Git with JDeveloper

JDeveloper uses a Git extension to perform Git tasks in the IDE. You can download the Git extension from the Help menu. Open the Help menu and select Check for Updates. See the JDeveloper documentation for more information.

You can also use the JDeveloper Oracle Developer Cloud Service Team Server plug-in to clone and manage Git repositories. Using the Team Server plug-in, you can add the JDeveloper application into the specific Git repository and then follow the wizard to commit and push the updates. You can also use the Team Server to track issues, and monitor builds of the project. See Using the Oracle Developer Cloud Service Team Server and Using Oracle JDeveloper with Oracle Developer Cloud Service.

To clone a remote Git repository in JDeveloper:

  1. Open JDeveloper.

  2. From the Team menu, select Git, then Clone.

  3. In the Welcome page of the Clone from Git wizard, click Next. No action is required in the Welcome page.

  4. In the Remote Repository page, enter the URL of the project’s Git repository in Repository URL, user name in User Name, password in Password, and click Next.

    See Viewing and Copying a Git Repository’s Access URL to get the Git repository’s URL.

    If you are using the SSH URL to access the repository, create an SSH key and add it to Oracle Developer Cloud Service. See Generating an SSH Key. Also, in the Remote Repository page, instead of entering the password, select the Private Key File.

  5. In the Destination page, specify the path of the cloned Git repository in Destination, name of the repository in Clone Name, and the branch to checkout in Checkout Branch. Click Next.

  6. In the Git Clone Summary page, verify the remote repository URL, user name, remote branches to checkout, local repository path, clone name, the checkout branch, and click Finish.

  7. In the New Files Dialog, if prompted, select the desired option and click OK.

For more information about how to add a JDeveloper application to the cloned Git repository, manage branches, commit and push commands, read the JDeveloper Git documentation in Oracle Fusion Middleware Developing Applications with Oracle JDeveloper at http://docs.oracle.com/middleware.

Pushing an Existing Local Git Repository to an Empty Oracle Developer Cloud Service Git Repository

If your application source code is already available in a local Git repository, you can push it to the empty remote Git repository of your project.

If your application source code files exist in a remote Git repository of another project or an external remote Git repository, you can import the repository to the remote Git repository of your project. The remote repository of the project must be empty. See Importing a Git Repository for more information.

You can either use the Git command line interface or the Git integration available in IDEs to push the local Git repository to the remote Git repository.

Using the Git Command Line Interface

If you are comfortable using a command line interface, download and install the Git command line tool. After downloading the command line tool, set up and customize your Git environment. For more information, see Using the Git Command Line Interface.

Before you push the local Git repository, verify that you have committed all files to the local Git repository and the remote Git repository is empty.

To push a local Git repository to the remote repository:

  1. Open the Git command line interface.

  2. Navigate to the directory that contains your Git repository.

  3. Use the git remote add <remote_repo_name> <remote_repo_url> command to add the remote Git repository of your Oracle Developer Cloud Service project to the local Git repository. See Viewing and Copying a Git Repository’s Access URL to get the Git repository’s URL.

    See Viewing and Copying a Git Repository’s Access URL to get the Git repository’s URL.

    HTTPS Example: git remote add origin https://john.doe%40oracle.com@developer.us.oraclecloud.com/developer1111-usoracle22222/s/developer1111-usoracle22222_myproject/scm/developer1111-usoracle22222_myproject.git

    SSH example:

    git remote add origin ssh://usoracle22222.john.doe%40oracle.com@developer.us.oraclecloud.com/developer1111-usoracle22222_myproject/developer1111-usoracle22222_myproject.git

    The above example adds a remote named origin for the repository at developer.us.oraclecloud.com/developer1111-usoracle22222_myproject/developer1111-usoracle22222_myproject.git.

    Note:

    If you are using the SSH URL to access the repository, create an SSH key and add it to Oracle Developer Cloud Service. See Generating an SSH Key

  4. Use the git push command to push the files of the desired branch to the remote Git repository.

    Example: git push -u origin master

  5. In the Oracle Developer Cloud Service web user interface, click Code in the navigation bar and view the files in the remote Git repository.

For more information about Git commands, see http://git-scm.com/docs.

Tip:

If you want to create a local Git repository, you can use the git init command in an empty directory. Initialization creates an empty Git repository in the specified directory with a master branch. A .git subdirectory containing metadata of the Git repository is also created. After creating the local Git repository, you can add files to the directory and commit them.

Using Git with Eclipse IDE

Eclipse IDE and OEPE use EGit, an Eclipse Team provider for Git, to access and manage Git repositories.

Before you push the local Git repository, verify that you have committed all files to the local Git repository and the remote Git repository is empty.

To push a local Git repository to the remote Git repository:

  1. In the IDE, open the Git Repositories view.

    From the Window menu, select Show View, and select Git Repositories. If Git Repositories is not listed, click Other. In the Show View dialog, expand Git, select Git Repositories, and click OK.

  2. In the Git Repositories view, click Add an existing local Git repository.

    Tip:

    If you want to create a local Git repository, click Create a new local Git repository. After creating the repository, add the IDE project it and commit the files. For more information, see Creating Repositories and Committing Changes topics in the EGit documentation at http://wiki.eclipse.org/EGit/User_Guide.

  3. In the Add Git Repositories dialog, click Browse, select the Git repository directory, and click OK.

    In Search Results, select the check box of the Git repository, and click Finish.

  4. In the Git Repositories view, right-click the repository root, select Remote, and then select Push from the submenu.

  5. In the Push to Another Repository dialog, complete the elements using the descriptions in the following table.

    Element Description

    Location: URI

    Enter the URL of the remote Git repository.

    See Viewing and Copying a Git Repository’s Access URL to get the Git repository’s URL.

    Based on the URL, the Host, Repository path, Protocol, Port, and User fields are automatically populated.

    If you are using the SSH URL to access the repository, create an SSH key and add it to Oracle Developer Cloud Service. See Generating an SSH Key

    Authentication: Password

    Enter the password.

    Click Next.

  6. In the Push Ref Specifications page, specify the Source ref and Destination ref, and click the Add Spec to add the spec to Specifications for push list.

  7. Click Finish.

  8. In the Push Results dialog, click OK.

  9. In the Oracle Developer Cloud Service web user interface, click Code in the navigation bar and view the files in the remote Git repository.

For more information about EGit and its commands, read the following sections of the EGit documentation at http://wiki.eclipse.org/EGit/User_Guide:

  • Configuration in Getting Started to set up and customize EGit

  • Starting from existing Git Repositories

  • Working with remote Repositories

  • Push Upstream and Pushing to other Repositories

Using Git with NetBeans IDE

NetBeans IDE uses a Git plugin to perform Git tasks in the IDE.

Before you push the local Git repository, verify that you have committed all files to the local Git repository and the remote Git repository is empty.

To push a local Git repository to the remote repository:

  1. Open the Git Repository browser in NetBeans IDE.

    From the Team menu, select Git, and then select Repository Browser.

    Tip:

    If you want to create a local Git repository, click Initialize Repository. After creating the repository, add the NetBeans IDE project to it and commit the files. See Initializing a Git Repository and Committing Sources to a Repository topics in the NetBeans IDE and Git documentation at https://netbeans.org/kb/docs/ide/git.html.

  2. In the Git Repository Browser window, right-click, and select Open Repository.

  3. In the Open dialog, browse, select the local Git repository directory, and click Open.

  4. In the Git Repository Browser window, right-click the repository root, select Remote, and then select Push.

  5. In the Remote Repository page of the Push to Remote Repository dialog, select the Specify Git Repository Location option, enter the remote Git repository URL in Repository URL, and the password in Password. Click Next.

    If you are using the SSH URL to access the repository, create an SSH key and add it to Oracle Developer Cloud Service. See Generating an SSH Key

  6. In the Select Local Branches page, select the check box of the branch you want to push, and click Next.

  7. In the Update Local References page, verify that the remote branch check box is selected, and click Finish.

    To continue tracking the repository updates, click Yes.

  8. In the Oracle Developer Cloud Service web user interface, click Code in the navigation bar and view the files in the remote Git repository.

For more information about Git commands in NetBeans IDE, read the Working with Remote Repositories section of the NetBeans IDE and Git documentation at https://netbeans.org/kb/docs/ide/git.html:

Using Git with JDeveloper

JDeveloper uses a Git extension to perform Git tasks from the IDE. You can download the Git extension from the Help menu. Open the Help menu and select Check for Updates. See the JDeveloper documentation for more information.

To push the local Git repository application to the remote repository:

  1. In JDeveloper, open the application that is initialized in the local Git repository.

    Tip:

    If you want to create a local Git repository, create or open the application, and from the Team menu, select Git, then Initialize. After creating the application, add project files to it and commit them. See How to Set Up and Configure a Git Repository and How to Work with New and Changed Files in Git in Oracle Fusion Middleware Developing Applications with Oracle JDeveloper at http://docs.oracle.com/middleware.

  2. From the Team menu, select Git, and then Push.

  3. In the Welcome page of the Push to Git wizard, click Next. No action is required in the Welcome page.

  4. In the Remote Repository page, enter the URL of the project’s Git repository in Repository URL (see Viewing and Copying a Git Repository’s Access URL to get the Git repository’s URL), user name in User Name, password in Password, and click Next.

    If you are using the SSH URL to access the repository, create an SSH key and add it to Oracle Developer Cloud Service. See Generating an SSH Key. Also, in the Remote Repository page, instead of entering the password, select the Private Key File.

  5. In the Local Branch page, select the check box of the branch that you want to push, and click Next.

  6. In the Git Push Summary page, verify the remote repository URL, user name, remote branch, local repository path, and click Finish.

  7. In the Oracle Developer Cloud Service web user interface, click Code in the navigation bar and view the files in the remote Git repository.

For more information about Git commands in JDeveloper, read the following sections of Oracle Fusion Middleware Developing Applications with Oracle JDeveloper at http://docs.oracle.com/middleware:

  • Setting Up and Configuring a Source Repository

  • Moving Files from Remote Repositories in Git