|
| 1 | +--- |
| 2 | +title: "Creating Oracle Code Repositories using the oci CLI" |
| 3 | +description: "Fast track repository creation using the oci command line tool." |
| 4 | +date: 2023-01-26 12:00 |
| 5 | +parent: [tutorials] |
| 6 | +--- |
| 7 | +The first thing you need to do to start using Code Repositories is to create a Project to host your new repository. If you already have a project, you'll just need its OCID and you can skip to the next section. |
| 8 | + |
| 9 | +1. Navigate to [cloud.oracle.com][1] |
| 10 | +2. Click the "hamburger" icon in the upper left. |
| 11 | +3. Type "projects" in the search field, then click "Projects DevOps" on the right. |
| 12 | + |
| 13 | + ![Screenshot of: Type "projects" in the search field, then click "Projects DevOps" on the right.][3] |
| 14 | +4. Click the "Choose a compartment" field and select your compartment. |
| 15 | + |
| 16 | + ![Screenshot of: Click the "Choose a compartment" field and select your compartment.][4] |
| 17 | + |
| 18 | +5. Click "Create devops project" |
| 19 | + |
| 20 | + ![Screenshot of: Click "Create devops project"][5] |
| 21 | +6. Type a name for your project, in this case I'm using RepositoryDemo |
| 22 | + |
| 23 | +7. Click "Select topic" |
| 24 | + |
| 25 | +8. You need to assign a topic to the project. If you don't have any topics available, you'll need to add at least one to your instance. |
| 26 | + |
| 27 | + ![Screenshot of: Click "Select topic"][6] |
| 28 | + |
| 29 | + ![Select topic][7] |
| 30 | +9. Click "Create devops project" |
| 31 | + |
| 32 | + ![Screenshot of: Click "Create devops project"][8] |
| 33 | + |
| 34 | + |
| 35 | +[1]: https://cloud.oracle.com/ |
| 36 | +[2]: assets/code-repo-step1.jpg |
| 37 | +[3]: assets/code-repo-step2.jpg |
| 38 | +[4]: assets/code-repo-step3.jpg |
| 39 | +[5]: assets/code-repo-step4.jpg |
| 40 | +[6]: assets/code-repo-step5.jpg |
| 41 | +[7]: assets/code-repo-step6.jpg |
| 42 | +[8]: assets/code-repo-step7.jpg |
| 43 | + |
| 44 | +Take note of the OCID of the new project, you'll need it in the next steps. You can just click on "Copy" next to the OCID label to copy the (rather long) string to your clipboard automatically. |
| 45 | + |
| 46 | +### Creating the repository |
| 47 | + |
| 48 | +Once you have a Project created, you can use the `oci` command line tool to generate a repo. You can do this either in the Cloud Shell, or in you local Terminal if you have `oci` installed. |
| 49 | + |
| 50 | +To create a repository, we'll use [`oci create`](https://docs.oracle.com/iaas/tools/oci-cli/latest/oci_cli_docs/cmdref/devops/repository/create.html). |
| 51 | + |
| 52 | + oci devops repository create --name "NAME-OF-PROJECT" --project-id "OCID_FOR_PROJECT" --repository-type HOSTED --query 'data.["http-url","ssh-url"]' |
| 53 | + |
| 54 | +`--name` is the name of the project for which you're creating the new repo. `--project-id` needs to be the OCID for the project, which you can copy from the project overview in the console. The `--repository-type` should be HOSTED to create a repository you can remotely access with SSH. Adding the `--query` to the end will return the HTTP and SSH urls for the new repository. |
| 55 | + |
| 56 | +You can also retrive the SSH URL for all repositories using the `list` command: |
| 57 | + |
| 58 | + oci devops repository list --project-id "OCID_FOR_PROJECT" |
| 59 | + |
| 60 | +You'll see an entry for `ssh-url` in the response. |
| 61 | + |
| 62 | +Alternatively, you can grab the new ID for your repo at the time of creation and then use `repository get` to retrive the urls: |
| 63 | + |
| 64 | + repoId=$(oci devops repository create --name "NAME-OF-PROJECT" --project-id OCID_FOR_PROJECT --repository-type HOSTED --query 'data.id' | sed s'/[\[",]//g') |
| 65 | + |
| 66 | +Then use `repository get`: |
| 67 | + |
| 68 | + oci devops repository get --repository-id $repoId --query 'data.["http-url","ssh-url"]' |
| 69 | + |
| 70 | +### Using the repository |
| 71 | + |
| 72 | +1. First, create a new directory on your local machine where you want to store your code. This can be done by opening the command prompt or terminal and navigating to the desired location, then using the command `mkdir [directory name].` |
| 73 | +2. Next, initialize the directory as a Git repository by using the command `git init` within the newly created directory. |
| 74 | +3. Connect your local repository to a remote repository by using the command `git remote add origin [ssh URL from above]`. This allows you to push and pull code from the remote repository to your local machine. |
| 75 | +4. Create a new file in the directory, for example, `example.sql` and add some sample code to it. |
| 76 | +5. Use the command `git add [file name]` to add the new file to the repository. |
| 77 | +6. Use the command `git commit -m [commit message]` to commit the changes to the repository. |
| 78 | +7. Finally, use the command `git push origin master` to push the changes to the remote repository. |
| 79 | + |
| 80 | +Your Oracle code repository is now set up and ready to use. You can continue to add and commit code changes as needed, and use the `git pull` command to retrieve updates from the remote repository. |
0 commit comments