Chapter 1. Git basics in CodeReady Studio

CodeReady Studio includes Git Perspective that allows developers to manage their Git repositories from a graphical interface. The following section outlines the basic workflow of a Git project in Git Perspective and how to accomplish the most common Git-related tasks.

The following section describes how to:

  • Set up Git Perspective.
  • Manage repositories in Git Perspective.
  • Manage branches in Git Perspective.
  • Manage commits in Git Perspective.

1.1. Setting up Git Perspective

The following section describes how to open Git Perspective in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Click WindowPerspectiveOpen PerspectiveOther.

    The Open Perspective window appears.

  3. Select Git.
  4. Click the Open button.

    The Git Repositories view appears.

1.2. Managing repositories in Git Perspective

The following section describes how to use Git Perspective to:

  • Create a new Git repository.
  • Add an existing local Git repository.
  • Clone an existing Git repository.
  • Add a remote for the repository.

1.2.1. Creating a new Git repository

The following section describes how to use Git Perspective to create a new Git repository.

Procedure

  1. Start CodeReady Studio.
  2. Start Git Perspective.
  3. Click the Create a new Git Repository and add it to this view icon.

    Figure 1.1. Click the Create a New Git Repository button

    Click the Create a new Git Repository button

    The Create a Git Repository window appears.

    A path to the default Repository directory is generated. If you are satisfied with the default path, continue with the repository creation. Alternatively, you can select the option to Create as bare repository.

    Note

    Bare repositories are recommended for central repositories, not for development environments. Bare repositories do not contain a working or checked out copy of any source files. This prevents editing files and committing changes. Additionally, they store the Git revision history for your repository in the root folder instead of a .git sub-folder.

  4. Click the Create button.

    A new Git repository is created on your local machine and is now listed in the Git Repositories view.

1.2.2. Adding an existing local Git repository

The following section describes how to use Git Perspective to add a local Git repository to the IDE.

Procedure

  1. Start CodeReady Studio.
  2. Start Git Perspective.
  3. Click the Add an existing local Git Repository to this view icon.

    Figure 1.2. Click the Add an existing local Git Repository icon

    Click the Add an existing local Git Repository icon

    The Add Git Repositories window appears.

  4. Click the Browse button to locate your local Git repository.

    Optionally, select the Look for nested repositories check box to search for nested repositories.

  5. Check the path to the appropriate .git file in the Search results field.
  6. Click the Add button

The local repository is now listed in the Git Repositories view.

1.2.3. Cloning an existing Git repository

The following section describes how to use Git Perspective to create a local clone of the repository that already exists online (GitHub, GitLab).

Procedure

  1. Start CodeReady Studio.
  2. Start Git Perspective.
  3. Clone the source repository with HTTPS or SSH.
  4. Click the Clone a Git Repository and add the clone to this view icon.

    Figure 1.3. Click the Clone a Git Repository icon

    Clone a Git Repository and add the clone to this view icon

    The Clone Git Repository window appears.

  5. Add the address for the source repository to the URI field.

    The Host and Repository path fields are populated automatically.

  6. Click the Next button.
  7. Select the branches you want to clone.
  8. Click the Next button
  9. Ensure that the Directory path and Initial branch are set correctly.

    Optionally, you can customize the Remote name and choose the appropriate working sets by selecting the Add project to working sets check box.

  10. Click the Finish button.

The new cloned repository is now listed in the Git Repositories view.

1.2.4. Adding a remote for the repository

After setting up your repository in Git Perspective for the first time, set up a remote for the repository. This is a one-time set up step for newly created or added repository.

The following section describes how to use Git Perspective to set up the remote for your repository.

Procedure

  1. Start CodeReady Studio.
  2. Start Git Perspective.
  3. Expand the target repository in the Git Repositories view.
  4. Right-click RemotesCreate Remote.

    The New Remote window appears.

  5. Name your remote.
  6. Ensure that the Configure push is selected.
  7. Click the Create button.

    The Configure Push window appears.

  8. Click the Change button.

    The Select a URI window appears.

  9. Add the URI, username and password for the source repository.

    The Host and Repository path fields are populated automatically.

  10. Click FinishSave.

Verification steps

  • Expand the target repositoryRemotes in the Git Repositories view. Your newly added remote is now listed in there.

1.3. Managing branches in Git Perspective

The following section describes how to use Git Perspective to:

  • Create a new branch.
  • Work in the new branch.
  • Submit a pull request.

1.3.1. Creating a new branch

The following section describes how to use Git Perspective to create a new branch.

Procedure

  1. Start CodeReady Studio.
  2. Start Git Perspective.
  3. Expand the target repositoryBranchesRemote Trackingorigin to view all the remote branches.
  4. Right-click masterCreate Branch…​.

    The Create Branch window appears.

  5. Select the source of the new branch.
  6. Name the branch.
  7. Select the Configure upstream for push and pull and Checkout new branch check boxes.
  8. Select the appropriate option in the When pulling field.
  9. Click the Finish button.

Verification

  • Expand the target repositoryBranchesLocal in the Git Repositories view. Your newly added branch is now listed there.

1.3.2. Working in the branch

The following section describes how to open a built-in terminal in Git Perspective.

Procedure

  1. Start CodeReady Studio.
  2. Start Git Perspective.
  3. Press Shift+Ctrl+Alt+T.

    The Launch Terminal window appears.

  4. Choose Local Terminal.
  5. Set Encoding to Default (ISO-8859-1).
  6. Click the OK button.

    The Terminal window now displays the command-line terminal.

Note that as default, the current working directory is the home directory of your current user.

1.3.3. Submitting a pull request

It is strongly recommended to update your local repository before merging your changes, especially when working in a shared repository.

The following section describes how to use Git Perspective to submit a pull request (PR).

Procedure

  1. Start CodeReady Studio.
  2. Start Git Perspective .
  3. Right-click the target repositoryPull.

    The Pull Request window appears.

  4. Click the Close button.

Now the changes from the remote repository are merged into your local repository.

1.4. Committing and pushing the changes

The following section describes how to commit and push the changes in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Start Git Perspective.
  3. Right-click on the target repositoryCommit.

    The Git Staging view appears.

  4. Select the changes you want to stage.
  5. Click the Add selected files to the index button to stage the changes you want to commit.

    Figure 1.4. Stage files to commit

    Stage files to commit
  6. Add a commit message to the Commit Message field.

    Author and Committer fields are populated automatically.

  7. Click the Commit button to commit your changes, or the Commit and Push button to commit your changes and push them to the remote repository.

    Note that when selecting the Commit and Push option you are prompted to enter the repository address, and your access username and password for that repository.