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 the Commit icon at the bottom of the menu.

To copy the revision name to the clipboard, click Copy the Copy icon. 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

git-cvsimport

For more information, see http://git-scm.com/docs/git-cvsimport.

Subversion (SVN)

git svn

For more information, see http://git-scm.com/docs/git-svn.

Other version control system

See the Git Book at http://git-scm.com/book/es/v2/Git-and-Other-Systems-Migrating-to-Git.

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.

the project owner icon 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 Project Home page
  • Git Git page
  • Project Administration Gear: Repositories page
Create an Empty Git Repository
  1. Click + Create Repository.
  2. In the New Repository dialog box, in Name and Description, enter a unique name and a description.
    After you create a repository, you can’t change its name.
  3. In Initial Content, select the Empty Repository option.
    To initialize the repository with a file, select the Initialize repository with README file option.

    You can add to and format the contents of the readme file using the Markdown markup language. If you don’t want to keep the file after DevCS creates the repository, you can delete it.

  4. Click Create.
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.

When you import an external Git repository, DevCS creates a Git repository in the project and copies the branches, tags, and commit history to it from the external Git repository. No changes made to the external Git repository after the import succeeds are reflected in the imported Git repository.
  1. Click + Create Repository.
  2. In the New Repository dialog box, in Initial content, select Import existing repository.
  3. In the text box, enter the URL of in the external Git repository.
    If the imported Git repository is password protected, enter the repository credentials in Username and Password. Note that DevCS doesn’t store the credentials.
  4. Click Create.
You can also import an existing Git repository to an empty project Git repository from the Git page. If the added hosted Git repository is empty, enter the Git repository’s URL in the Import existing repository section of the Git page. Enter repository credentials, if required, and click Import.
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.

Note that you can’t add or update files or manage branches of a mirrored Git repository from the Git page of the project.

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.

  1. In the navigation bar, click Project Administration Gear.
  2. Click Repositories.
  3. Under External Repositories, click + Link External Repository.
  4. In the New Repository dialog box, enter the URL of the external Git repository in URL and the repository description in Description.
  5. Expand the Credentials for non-public repos section and provide the credentials to access the external Git repository.

    In Username, enter the username of the external repository account. In Token, enter the authentication token.

  6. Click Create.
The external repository is now available on the Git page and the Repositories tab of the Project Home page.

When you add an external Git repository, DevCS shows two URLs in the Clone drop-down menu of the repository.

Example:

Clone drop-down menu of the Git repository

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 the Options icon, 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 master branch of a Git repository is set as the default branch. However, you can set any branch as the default branch of a Git repository.

On the Project Settings: Repositories page, mouse over the Git repository name, click Options the Options icon, 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 the Options icon, and select Index.

Delete a Git repository

On the Project Settings: Repositories page, mouse over the Git repository name, click Options the Options icon, 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.

  1. 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 the Copy icon to copy the HTTPS or the SSH URL.

  2. Open the Git client. For example, the Git CLI.

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

  4. 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

  5. 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.

  6. Copy your application files to the cloned Git repository directory.

  7. 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 .

  8. 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"

  9. 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 the Tutorial icon 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.

  1. 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 the Copy icon to copy the HTTPS or the SSH URL.

  2. Open the Git client. For example, the Git CLI.

  3. Navigate to the local Git repository directory.

  4. 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 at developer.us.oraclecloud.com/developer1111-usoracle22222_myproject/developer1111-usoracle22222_myproject.git.

  5. 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

  6. In your project, open the Git page and check the files in the project’s Git repository.

Access a Git Repository using SSH

  1. On the computer that you'll use to access the Git repository, generate a SSH key pair and upload its private key to DevCS. See Upload Your Public SSH Key. Make sure that the private key on your computer is accessible to the Git client.
    Ignore this step if you've already uploaded the SSH public key.
  2. Copy the Git repository’s SSH 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 the Copy icon to copy the SSH URL.

  3. Open the Git client. For example, the Git CLI.
  4. Navigate to the directory where you want to clone the remote Git repository.
  5. Using the Git client, clone the project’s Git repository.

    For example, if you’re using the Git CLI, use the git clone <repository-ssh-url> command.

    Example:

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

    If you've already cloned the Git repository to your computer using HTTPS, use the git add remote command to add the SSH URL of the Git repository.

    Example:

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

  6. Commit the updated files to the cloned Git repository.
  7. Push the commit from the cloned Git repository to the hosted Git repository.

    Example:

    git push ssh-origin master

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.

the project user icon You must be a project member to add or updates files of a Git repository.

  1. In the navigation bar, click Git Git.
  2. From the Repositories drop-down list, select the Git repository. From the Revisions Revisions drop-down list, select the branch.
  3. On the right side of the page, click Files, if necessary.
  4. 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 the Root icon. To copy the path of a file or a directory, click Copy to clipboard the Copy icon.

Action How To

Add a file

  1. Click + File.
  2. In File Name, enter the name of the file along with its extension.
  3. In the code editor, enter file contents.
  4. Click Commit.
  5. 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.

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 / in the beginning.

Example:

  • Enter test/text_file.txt to save the text_file.txt file in the test directory on the current path. If the test directory doesn’t exist, it’s created.
  • Enter /test/text_file.txt to save the text_file.txt file in the test directory on the root. If the test directory doesn’t exist, it’s created.

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 the Right Scroll icon or Left Scroll the Left Scroll icon to scroll one character at a time.

To view the file in raw (unformatted) format in the web browser, click Edit the Edit icon, 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 .png, .jpg, .bmp, and .gif), it’s displayed in the browser. The contents of a binary file such as .zip and .rar aren’t displayed, but you can use the browser URL to download it.

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 the Edit icon. 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 the Actions icon next to Edit the Edit icon, 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: git clone https://john.doe%40example.com@developer.us.oraclecloud.com/developer1111-usoracle22222/s/developer1111-usoracle22222_myproject/scm/developer1111-usoracle22222_myproject.git

git add <filename>

Add a file that you've added to the repository's directory to the repository's index.

Example: git add readme.txt

To add all new files to the index, use git add --all

To add a directory and its contents to the index, navigate to the directory and use git add .

git rm <filename>

Remove a file from the repository.

Example: git rm readme.txt

git status

Check the status of added and edited files.

Example: git status

git branch

Create a branch.

Example: git branch new_branch

To list all existing branches of the repository, use git branch.

git checkout

Switch to (or checkout) a branch.

Example: git checkout new_branch

You can use the git checkout -b command to create a branch and switch to it immediately. Example: git branch -b new_branch

git merge

Merge a branch with the checked out branch.

Example: git merge new_branch

git commit Commit changes to the local Git repository.

Example: git commit -m "Initial commit"

git push Push commits to the project's Git repository.

Example: git push -u origin master

git pull

Incorporate changes from the project's Git repository to the local Git repository.

Example: git pull origin master

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 the Copy icon to copy the URL to clipboard. You may also select the URL and press Ctrl + C or use the mouse context menu to copy the URL to the clipboard.

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 2 of myfile.txt, click the line number 2. Clicking the line number updates the URL in the browser’s address bar to http://developer.us2.oraclecloud.com/my-org/#projects/demo/scm/demo.git/blob/myfile.txt?revision=master&sl=2. You can copy and use this URL to open myfile.txt in the demo.git repository – master branch with line number 2 selected.

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 Shift key pressed to select them. From the address bar of the browser, copy the URL.

Example: With the Shift key pressed, clicking line numbers 2 through 5 of myfile.txt selects those lines. The URL in the browser’s address bar changes to http://developer.us2.oraclecloud.com/my-org/#projects/demo/scm/demo.git/blob/myfile.txt?revision=master&sl=2–5. Copy the URL and share it with project members. When the URL is entered, the myfile.txt file of the demo.git repository – master branch opens with line numbers 2 through 5 selected.

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.

  1. From the Repositories drop-down list, select the Git repository. From the Revisions the Revisions icon menu, select the branch.

  2. 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.

  3. 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 the List icon toggle button.

To view the history of another branch or tag, in the text box to the right of the History the History icon 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 the Graph icon toggle button.

In the graph:

  • Each dot represents a commit.

    To see the details of the commit, click the dot.

  • A splitting line represents a branch.

  • Joining lines represent a merge.

  • Latest commits appear at the top of 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.

the project user icon You must be a project member to to create a branch.

Action How To

Create a branch from a base branch

  1. In the Refs view of the Git page, click Branches Branches.

  2. From the Repositories drop-down list, select the repository.

  3. Click + Create Branch.

  4. In the New Branch dialog box, in Name, enter the branch name. From the Base drop-down list, select the base revision name.

  5. To mark the branch as a private branch, select the Private Branch check box.
  6. Click Create.

Create a branch from the head (tip) of another branch

  1. In the Refs view of the Git page, click Branches Branches.

  2. From the Repositories drop-down list, select the repository.

  3. Click + New Branch.

  4. In the branch list, to the right of source branch name, click Actions the Actions icon, and select Branch.

  5. In the New Branch dialog box, enter the name of the new branch.

  6. To mark the branch as a private branch, select the Private Branch check box.
  7. Click Create.

Create a branch from a tag

  1. In the Refs view of the Git page, click Tags Tags.

  2. From the Repositories drop-down list, select the repository.

  3. Click + New Branch.

  4. In the tags list, to the right of the tag name, click Actions the Actions icon and select Branch.

  5. In the New Branch dialog box, enter the name of the new branch.

  6. To mark the branch as a private branch, select the Private Branch check box.
  7. Click Create.

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.

the project owner icon You must be assigned the project Owner role to set restrictions on a branch.

  1. In the navigation bar, click Project Administration Gear.
  2. Click Branches.
  3. In Repository and Branches, select the Git repository and the branch.
  4. 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 master branch.

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.

  1. In the branch list, to the right of branch name, click Actions Actions, and select Rename.

  2. In the Rename Branch dialog box, in Name, enter the new branch name.

  3. Select the I want to rename the branch check box and click Rename.

Compare a branch

In the branch list, to the right of branch name, click Actions Actions, and select Compare. By default, the branch is compared with the master branch.

Protect or set restrictions on a branch In the branch list, to the right of branch name, click Actions Actions, and select Protection Settings.

Delete a branch

You can’t delete a restricted branch or the master branch.

After you delete a branch, you must update, close, or remove all related merge requests, build jobs, and deployment configurations.

  1. In the branch list, to the right of branch name, click Actions Actions, and select Delete.

  2. In the Delete Branch dialog box, select the I want to delete the branch check box, and Delete.

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

  1. In the Refs view of the Git page, click Tags Tags.

  2. From the Repositories drop-down list, select the repository.

  3. Click + New Tag.

  4. In the New Tag dialog box, in Name, enter the tag name. In Base, enter the base revision name. Click Create.

Rename a tag

  1. In the tags list of the Tags Tags view, to the right of the tag name, click Actions and select Rename.

  2. In the Rename Tag dialog box, in New Name, enter the new tag name, select the I want to rename the tag check box, and click Rename.

Compare a tag

In the tags list of the Tags Tags view, to the right of the tag name, click Actions 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 Tags view, to the right of the tag name, click Actions 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.

  1. On the right side of the Git page, click Compare.
  2. From the Base Revision Base Revision drop-down list on the left, select the base revision.
    By default, the Git page selects the last commit of the repository as the base revision and the selected revision as the compare revision.
  3. From the Compare Revision Compare Revision drop-down list on the right, select the compare revision.

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 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 RevisionsFrom 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 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 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.

  1. Browse and open the file.
  2. On the right side of the page, click Logs.
  3. For the commit that changed the file and added the changes you want to comment on, click the button with the first seven characters of the commit’s SHA-1 checksum hash as the label.
  4. In the Changed Files tab of the Compare view, mouse-over the line number of the file and click Add Comment Add Comment
    If you selected the Unified view, click the line number in the second column. If you selected the Side by Side view, click the line number of the file on the right.
  5. In the Leave a comment box, enter the comment, and click Comment.
The comment is added as an inline comment to the file and is visible to all project members. To reply to a comment, click Reply reply, enter the comment in the Leave a reply box, and click Comment.

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

  1. Open the project.

  2. In the navigation bar, click Git Git.

  3. On the right side of the page, click Refs.

  4. If necessary, click Branches Branches.

  5. In the branch list, to the right of the branch name, click cc.

    Alternatively, click Actions Actions, and select Subscribe.

A Subscribed the check mark 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

  1. From the Repositories drop-down list, select the Git repository. From the Revisions the Revisions icon drop-down list, select the revision.

  2. In the top-right corner of the page, in the Search Code box, enter the search term or select it from the suggestion list.

  3. Click Search the Search icon.

Search for a term in all revisions of a Git repository

  1. From the Repositories drop-down list, select the Git repository. From the Revisions Revisions drop-down list, select the revision.

  2. In the top-right corner of the page, in the Search Code box, enter the search term or select it from the suggestion list.

  3. Click Search the Search icon.

  4. In the Revisions the Revisions icon drop-down list, click Reset the Reset icon.

    The Revisions the Revisions icon drop-down list now shows All Revisions.

Search for a term in all Git repositories

  1. From the Repositories drop-down list, select the Git repository. From the Revisions Revisions drop-down list, select the revision.

  2. In the top-right corner of the page, in the Search Code box, enter the search term or select it from the suggestion list.

  3. Click Search the Search icon.

  4. From the Repositories drop-down list, select the All Repositories option, or click Reset the Reset icon.

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 the Back icon.

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

  1. In the Files view of the Git page, from the Repositories drop-down list, select the repository. From the Revisions the Revisions icon menu, select the branch.

  2. From the Clone drop-down list, click Download ZIP or Download TGZ.

Alternate method:

  1. In the Refs view of the Git page, click Branches Branches.

  2. From the Repositories drop-down list, select the repository.

  3. In the branches list, to the right of the branch name, click Actions, select Download, and then select zip or tgz.

Download the archive of a tag

  1. In the Refs view of the Git page, click Tags Tags.

  2. From the Repositories drop-down list, select the repository.

  3. In the tags list, to the right of the tag name, click Actions, select Download, and then select zip or tgz.