Manage Code Files Using Git Repositories
A project uses Git repositories hosted on Oracle Cloud to store and version control your application's source code files.
Git Concepts and Terms
Git is a distributed version control in which you clone the entire remote (or central) repository, including its history to your computer. You add and commit the files on your computer and, when you’re done, push the commits to the remote repository.
If you are new to Git, read the Git documentation at https://git-scm.com/book/
and http://git-scm.com/doc
to learn more about Git repositories and Git basics, such as remote repositories, cloning, commits, pushes, SHA-1 checksum hashes, branches, and tags.
Here are the terms that this documentation uses to describe the Git terms and components of a project.
Term | Description |
---|---|
Project Git repository |
A remote or hosted Git repository of your project. A project can host multiple Git repositories. You can view all Git repositories from the Repositories drop-down list on the Git page. |
Local Git repository |
A cloned Git repository on your computer. |
External Git repository |
A Git repository that’s hosted outside the project. It could be a Git repository of another project, or a Git repository available on another platform, such as GitHub or Bitbucket. |
Revision |
A snapshot of the Git repository at a given time. The revision could be a branch, tag, or a commit. The Revisions menu displays the revisions (branches, tags, and commits) of the selected Git repository. When entering a search criteria, add a space at the end of the search term to search for an exact match. To search for a commit, in the search box at the top of the menu, enter the first three characters of the SHA-1 checksum hash of the commit. The commit that matches the search term appears next to Commit at the bottom of the menu. To copy the revision name to the clipboard, click Copy . For example, while viewing files of a particular commit, you can copy the SHA-1 checksum hash of the commit. |
Files view |
Display the Git repository’s files and allows you to manage them. |
Logs view |
Displays the Git repository’s commit history in a list and graphical format. |
Refs view |
Displays the Git repository’s branches and tags and allows you to manage them. |
Compare view |
Compares and displays the differences between two revisions of a Git repository. |
Migrate to Git
If you’ve been using a version control system, such as CVS or Subversion and want to migrate to Git, you can use the Git commands in the Git command-line interface to migrate.
To migrate from ... | Use this command: |
---|---|
CVS |
For more information, see |
Subversion (SVN) |
For more information, see |
Other version control system |
See the Git Book at |
Set Up a Git Repository
To set up a Git repository for your project, create a repository in the project, and then upload application files to it. After you've set up the repository, all project users can access its files.
Create and Manage Git Repositories
You can add multiple Git repositories to a project. You can create an empty Git repository, a Git repository with a readme file, or import files from another Git repository.
You may want to create an empty repository if you plan to upload your application files to it from your computer or import files from another Git repository. Some IDEs and Git clients can’t clone an empty Git repository. If this is the case with the IDE or Git client you use, you may want to create a Git repository initialized with a file.
You must be assigned the project Owner role to create and manage Git repositories.
You can create a Git repository from these pages:
- Repositories tab of the Project Home page
- Git page
- Project Administration : Repositories page
Import an External Git Repository
If you’ve been using a Git repository on another platform such as GitHub or Bitbucket, you can import files from the external Git repository to your project’s Git repository.
Mirror an External Git Repository
If you’ve been using a Git repository on another platform, such as GitHub or Bitbucket, and don’t want to import it to a project’s Git repository, you can mirror it in DevCS. Mirroring copies the repository to DevCS and then DevCS automatically synchronizes its files time to time. In an active DevCS project, the repositories are synchronized approximately every five minutes, but the duration may vary as it depends on the number of external Git repositories in all projects of the DevCS organization.
If the external Git repository is a private repository (or password protected), you must create an authentication token, such as GitHub's personal access token or BitBucket's App Password, and use it to provide access to the external Git repository. Don’t provide your account’s password.
When you add an external Git repository, DevCS shows two URLs in the Clone drop-down menu of the repository.
Example:
Use the external address URL (the first URL in the menu) to access the repository directly. You may want to use it to access the repository's updates immediately, but would need to enter credentials to access a private repository. Use the internal address URL (the second URL in the menu) to access the mirrored repository. You may want to use it to access a private repository as it doesn't require credentials.
Manage a Git Repository
After you’ve created a Git repository, you can edit its description, set its default branch, index it, and delete it. However, you can’t change its name.
Action | How To |
---|---|
Edit a Git repository’s description |
On the Git page, from the Repositories drop-down list, select the Git repository. In the Files or Logs view, click the repository description to edit it. Alternatively, on the Project Settings: Repositories page, mouse over the Git repository name, click Options , and select Edit. In the Description field of the Edit Repository dialog box, enter or edit the repository description, and click Update. |
Set the default branch |
When you open a Git repository on the Git page, the contents of the default branch are displayed. By default, the On the Project Settings: Repositories page, mouse over the Git repository name, click Options , and select Edit. From the Default Branch drop-down list of the Edit Repository dialog box, select the branch, and click Update. |
Index a Git repository |
Indexing a Git repository creates or updates the Git repository index file with the latest changes. A Git index file is a binary file that serves as a virtual staging area for the next commit and contains a sorted list of object path names, along with permissions and the SHA-1 of a blob object. To index a repository, on the Project Settings: Repositories page, mouse over the Git repository name, click Options , and select Index. |
Delete a Git repository |
On the Project Settings: Repositories page, mouse over the Git repository name, click Options , and select Delete. In the Remove Repository dialog box, click Yes. |
Upload Files From Your Computer to the Project’s Git Repository
To upload your application source code files from your computer to the project’s Git repository, you can start by using a Git client to clone the project’s Git repository to your computer. After cloning, you can add files, commit the changes to the cloned Git repository, and then push the commit to the project’s Git repository.
-
Copy the project Git repository’s URL.
On the Git page, from the Repositories drop-down list, select the Git repository. From the Clone drop-down list, click Copy to clipboard to copy the HTTPS or the SSH URL.
-
Open the Git client. For example, the Git CLI.
-
Navigate to the directory where you want to clone the remote Git repository.
-
Using the Git client, clone the project’s Git repository.
For example, if you’re using the Git CLI, use the
git clone <repository-url>
command. Use the Git repository’s URL copied from step 1.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
-
Open the directory to access files.
You’d notice a
.git
subdirectory in the repository directory. Don’t add, delete, or modify the files of the.git
subdirectory. -
Copy your application files to the cloned Git repository directory.
-
To add new files to the repository, use the Git client to add them to the repository index.
For example, if you’re using the Git CLI, use the
git add
command.git add readme.txt
To add a directory and its files, navigate to the directory and use
git add .
-
Commit the updated files to the cloned Git repository.
For example, if you are using the Git CLI, use the
git commit
command to save the changes.git commit -am "Sample comment"
-
Push the commit from the cloned Git repository to the hosted Git repository.
For example, if you are using the Git CLI, use the
git push
command.git push origin master
See this Tutorial to set up a Git repository and add files to it using the Git CLI.
Push a Local Git Repository to the Project’s Git Repository
If your application source code files are available in a local Git repository, you can push them to a project’s empty Git repository.
You can use any Git client to push the local Git repository to the remote Git repository.
-
Copy the URL of the project’s Git repository.
On the Git page, from the Repositories drop-down list, select the Git repository. From the Clone drop-down list, click Copy to clipboard to copy the HTTPS or the SSH URL.
-
Open the Git client. For example, the Git CLI.
-
Navigate to the local Git repository directory.
-
Add the project’s Git repository as the remote repository of the local repository. Use the Git repository’s URL copied from step 1.
For example, if you’re using the Git CLI, use the
git remote add <remote-repository-name> <repository-url>
command.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 atdeveloper.us.oraclecloud.com/developer1111-usoracle22222_myproject/developer1111-usoracle22222_myproject.git
. -
Push the local Git repository to the project’s Git repository.
For example, if you’re using the Git CLI, use the
git push
command.git push —u origin master
-
In your project, open the Git page and check the files in the project’s Git repository.
Add and Manage Files of a Git Repository
You can add and update files of a Git repository online from the Git page or clone the Git repository to your computer and update the files locally.
Manage Files from the Git Page
You can browse, add, edit, view commit history, rename, and delete files of a Git repository. You can’t add or update files of a linked external Git repository.
You must be a project member to add or updates files of a Git repository.
- In the navigation bar, click Git .
- From the Repositories drop-down list, select the Git repository. From the Revisions drop-down list, select the branch.
- On the right side of the page, click Files, if necessary.
- Browse and click a directory name to open it.
To go back to a file or a sub-directory of a parent directory, click / and select the file or directory from the menu. To go to the root directory, click . To copy the path of a file or a directory, click Copy to clipboard .
Action | How To |
---|---|
Add a file |
To save the file in a new directory or a directory structure, in File Name, enter the file path. You can enter a relative path or an absolute path. To specify an absolute path, add a Example:
|
View a file |
To view contents of a file, in the Files view, browse, and click the file name link. The file opens in the File view of the Git page. If you open a text file or an image file, its contents are displayed in a read-only editor. Contents of a binary file aren’t displayed.
If the text content exceeds the width of the editor, use the arrow keys to scroll left, right, up, and down. You can also use the scroll buttons to scroll horizontally. Move the cursor to the left or the right edge of the editor and click Right Scroll or Left Scroll to scroll one character at a time. To view the file in raw (unformatted) format in the web browser, click Edit , and select Raw. The contents of the opened file are displayed in a new tab or a window of the web browser. If the file is a text file or an image (such as |
View annotations and commits of a file |
Open the file and click Blame.
The Blame view displays annotations of the open file for each updated code line (or group of code lines) with commit information. The annotation includes commits that affected code lines, author, the date-time stamp of the commit, and the commit message. |
Edit, rename, or move a file |
Open the file and click Edit . Edit the file’s contents in the code editor. To rename the file or move it to another directory, in the file name text box, enter the new name or path. Click Commit to save. |
Delete a file |
To delete a file, click Actions next to Edit , and select Delete. In the Commit Changes dialog box, enter the commit summary in the first text box and details in the Details text box, and click Commit. |
Use Git Commands to Manage Files from Your Computer
To access and manage your project’s Git repository files from your computer, use a Git client, such as the Git CLI.
This table lists common Git commands that you can run in the Git CLI to work on files in your local Git repository.
Run this command ... | To: |
---|---|
git clone <repository-url> |
Clone a project's Git repository to your computer.
Example: |
|
Add a file that you've added to the repository's directory to the repository's index. Example: To add all new files to the index, use To add a directory and its contents to the index, navigate to the directory and use |
|
Remove a file from the repository. Example: |
|
Check the status of added and edited files. Example: |
|
Create a branch. Example: To list all existing branches of the repository, use |
|
Switch to (or checkout) a branch. Example: You can use the |
|
Merge a branch with the checked out branch. Example: |
git commit |
Commit changes to the local Git repository.
Example: |
git push |
Push commits to the project's Git repository.
Example: |
|
Incorporate changes from the project's Git repository to the local Git repository. Example: |
To display the Git help index, run the git help
command. Run the git help git
command to open the help index in a web browser. To display help for a particular command, run git help <command>
.
Associate a DevCS Issue with a Commit
When you save changes to a Git repository, you may want to link a DevCS issue that’s assigned to you with the commit.
To associate an issue with a commit, add Task-URL: <issue-url>
in the commit message.
Example:
Update for Defect 4 Task-URL:https://john.doe%40oracle.com@developer.us.oraclecloud.com/developer1111-usoracle22222/s/developer1111-usoracle22222_myproject/task/4
If the commit is successful, the SHA-1 checksum hash of the commit is added to the issue. Open the issue in Issues page and verify the SHA-1 checksum hash in Commits under Associations.
Copy the URL of a Git Repository or a File
From the Git page, you can copy and share the URL of a Git repository, the URL of a file in the Git repository, and the URL of a line in a file of the Git repository.
Before you share the URL, remember that only members of the project can use the URL to access the file or clone the repository. If the project is a shared project, organization members can access files in the project’s repository or clone the repository, but they can’t update them.
Action | How To |
---|---|
Copy the URL of a Git repository |
To clone a Git repository or to access it using a Git client, you use the URL of the repository. You can copy the URL from the Repositories tab of the Project Home page, the Git page, and from the Project Settings: Repositories page. In the Repositories tab of the Project Home page or the Project Settings: Repositories page, search for the Git repository, and click the Clone drop-down list to see the HTTPS and SSH URLs of the repository. To the right of the URL, click Copy to copy the URL to clipboard. You may also select the URL and press The SSH URL of an external Git repository isn’t available. |
Copy the URL of a file |
In the Files view of the Git page, open the file. From the address bar of the browser, copy the URL. |
Copy the URL of a line in a file |
In the Files view of the Git page, open the file. On the left side of the line, in the number column, click the line number. The entire line is selected. From the address bar of the browser, copy the URL. Example: To copy the URL of line number |
Copy the URL of a group of lines in a file |
In the Files view of the Git page, open the file. On the left side of the line, in the number column, click the line numbers with the Example: With the |
View the History of Files and Repositories
You can use the Logs view of the Git page to view the commits, branching, and merging history of a file or Git repository and its revisions.
-
From the Repositories drop-down list, select the Git repository. From the Revisions menu, select the branch.
-
To view the commit history of a file, browse, and open the file.
Skip this step to view the commit history of the selected Git repository.
-
On the right side of the page, click Logs.
Action | How To |
---|---|
View the commit history in a list format |
In the Logs view, click the History List toggle button. To view the history of another branch or tag, in the text box to the right of the History toggle button, enter branch or tag names. You may also click the text box and select the revisions from the drop-down list. You can add multiple branches or tags. To view the history of all revisions of the selected Git repository, remove all revision names from the text box. |
View the commit history as a graph |
In the Logs view, click the History Graph toggle button. In the graph:
|
Use Branches
Branching lets you work on different features and updates at any time without affecting the original source code.
Before you start working on a new feature or update major portions of the source code, it’s considered a good practice to create a branch and commit your changes to the new branch. This way your changes don’t affect the original source code and are safe to test and review. To learn more about the Git branch workflow, read the Git Branching - Branching Workflows topic in the Git book at https://git-scm.com/book/en/v2/
.
By default, all Git repositories have one default master
branch. However, you can add more branches to the repository. You can also subscribe to email notifications for commits made to the repository’s branches, and you can compare, rename, and delete branches.
Create a Branch
From the Refs view of the Git page, you can create a branch from the base branch, from the head (tip) of an existing branch, or from a tag.
You can’t create a branch in an empty Git repository. You must first clone the repository to your computer, add and commit files to the default master
branch that’s automatically created, and then push the branch to the project Git repository. After the default master
branch is pushed to the project Git repository, you can create more branches.
You can also mark a branch as a private branch. Only branch owners can push commits to a private branch.
You must be a project member to to create a branch.
Action | How To |
---|---|
Create a branch from a base branch |
|
Create a branch from the head (tip) of another branch |
|
Create a branch from a tag |
|
Protect a Branch
By default, any project member can rename or delete a repository branch, and push or merge another branch into it. To protect a branch from these actions, set restrictions on the branch.
You must be assigned the project Owner role to set restrictions on a branch.
- In the navigation bar, click Project Administration .
- Click Branches.
- In Repository and Branches, select the Git repository and the branch.
- On the Branches page, set the restrictions.
Tip:
On the Refs page, you can also click the Open, Private, Requires Review, or the Frozen label of a branch to edit its protection settings.This table describes the various branch protection actions you can perform from the Branches page.
Action | How To |
---|---|
Requires review and restrict merge actions | Select the Requires Review option and configure the review options. See Set Review and Merge Restrictions on a Repository Branch. |
Restrict push actions to project owners and branch owners | Select the Private option.
To define branch owners, click Owners and select the user. You can select multiple users. Note that to push commits to a private branch from your computer, always use SSH. Also, to run a build of job that uses a private branch, configure the job to use SSH. |
Lock a branch | Select the Frozen option. No changes are allowed to a locked branch by any user. |
Prevent forced pushes to the branch | Select the Do not allow forced pushes check box. The check box isn't available when the Requires Review or the Frozen option is selected as force push aren't allowed on a review or a frozen branch. |
Prevent the rename and delete actions on the branch | Select the Do not allow renaming and deleting branch check box. The branch can be renamed or deleted after you deselect the check box. The check box isn't available when the Requires Review or the Frozen option is selected. |
Manage a Branch
After you create a branch, you can rename it, compare it with another branch of the Git repository, or delete it.
You must be a project owner or member to edit and update a branch. You can perform the branch management actions from the Refs view of the Git page.
Action | How To |
---|---|
Rename a branch |
You can’t rename a restricted branch or the After renaming a branch, update all related merge requests, build jobs, and deployment configurations to use the new branch name. When you rename a branch, Git creates a branch with the new name and transfers all content from the old branch to the new branch. After the transfer is complete, the old branch is removed.
|
Compare a branch |
In the branch list, to the right of branch name, click Actions , and select Compare. By default, the branch is compared with the |
Protect or set restrictions on a branch | In the branch list, to the right of branch name, click Actions , and select Protection Settings. |
Delete a branch |
You can’t delete a restricted branch or the After you delete a branch, you must update, close, or remove all related merge requests, build jobs, and deployment configurations.
|
Use Tags
Tagging lets you mark a specific point of time in the history of the repository. For example, you can create a tag to mark the Git repository state of an application’s stable state, before a release.
Create and Manage Tags
From the Refs view of the Git page, you can create and manage a Git repository’s tags.
You must be a project owner or member to create and manage a tag.
Action | How To |
---|---|
Create a tag |
|
Rename a tag |
|
Compare a tag |
In the tags list of the Tags view, to the right of the tag name, click and select Compare. On the Compare page that opens, by default, the tag is compared with the default branch. |
Delete a tag |
In the tags list of the Tags view, to the right of the tag name, click and select Delete. In the Delete Tag dialog box, select the I want to delete the tag check box and click Delete. |
Compare Revisions
You can compare any two revisions of a Git repository. The base revision indicates the starting point of the comparison and the compare revision indicates the end point of the comparison. The revision could be a branch, a tag, or a commit SHA-1 checksum hash.
You can compare these revisions:
-
Branch versus branch
-
Tag versus tag
-
Commit versus commit
-
Branch versus tag
-
Commit versus branch
-
Tag versus commit
On the Compare Result page, the Changed Files tab and the Commits tab. The Changed Files tab lists files that have changed between the base revision and the compare revision. The Commits tab lists all commits that have happened between the base revision and the compare revision since their common commit. The Commits tab is enabled if From Merge Base is selected in From Merge Base or Revisions .
Action | How To |
---|---|
Compare with a parent of the base revision |
From the Base Revision drop-down list, click the Parents tab, and then click the SHA-1 checksum hash of the parent commit. |
View differences between the base revision and the compare revision since the last common commit to both revisions |
From the From Merge Base or Revisions drop-down list, select From Merge Base (...) . Select Revisions (..) to show the differences between the heads (or tips) of the base revision and the compare revision. |
Switch the base revision and the compare revision |
Click Switch Base . |
Create or open a merge request |
If a merge request exists with the Compare Revision as the review branch, click the merge request button to open the merge request review page. If a merge request doesn’t exist, click + Merge Request to create a merge request with Base Revision as the target branch and the Compare Revision as the review branch. |
View the compare options |
Click Diff Preferences to view various compare options. |
Add Comments to a File
While comparing files, you can add inline comments to the source code changes made to a file. The comments are visible to all users of the project.
Watch a Git Repository
You can watch a Git repository branch and receive email notifications when any file of the branch is updated in the project’s Git repository.
To get email notifications, enable them in your user preferences, and then set up a watch on the branch from the Refs view of the Git page.
Action | How To |
---|---|
Enable email notifications |
In your user preferences page, select the SCM/Push Activities check box. |
Watch a branch |
A Subscribed icon appears indicating that you are subscribed to email notifications of the branch updates. To unsubscribe, click cc again. |
Search in Git Repositories
You can search for a file name, directory name, or a term in the source code files, file paths, and file revisions of the project’s Git repositories.
The search field supports common programming languages, such as HTML, JavaScript, CSS, and Java. You can use these features while searching terms:
-
Language-aware
-
Auto-suggest
-
Symbols (class and function names) and file names
-
CamelCase
Action | How To |
---|---|
Search for a term in a Git repository and a revision |
|
Search for a term in all revisions of a Git repository |
|
Search for a term in all Git repositories |
|
The search result page displays all files, file paths, and file revisions that contain or match the search term (or symbol). To reset the search, to the left of the Search Code box, click Back .
Download an Archive of a Git Repository
If a branch or a tag of a Git repository isn’t required and you plan to delete it, it’s considered a good practice to create an archive of it and back it up before you delete it. From the Refs view of the Git page, you can download the archive file (zip or tgz) of a Git repository branch or a tag.
Action | How To |
---|---|
Download the archive of a branch |
Alternate method:
|
Download the archive of a tag |
|