Chapter 1. Git basics in CodeReady Studio


CodeReady Studio includes Git Perspective, which 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 describes how to accomplish the most common Git-related tasks.

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 Window Perspective Open Perspective Other.

    crs perspectives

    The Open Perspective window appears.

    crs locating git perspective
  3. Select Git.
  4. Click Open.

    The Git Repositories view appears.

    crs git repo view

1.2. Managing repositories in Git Perspective

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. Open Git Perspective.
  3. Click the Create a new Git Repository and add it to this view icon.

    crs git perspective create a new git repo

    The Create a Git Repository window appears.

    crs creat a new git repo

    The path to the default Repository directory is generated automatically. Choose the path where you want your repository to be stored at and continue with the repository creation.

    Optionally, you can select the Create as bare repository check box.

    Note

    Bare repositories are recommended for central repositories, not for development environments. They do not contain a working or checked out copy of any source file. 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 Create.

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

    crs new git repo

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

Procedure

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

    crs git perspective add a local git repo

    The Add Git Repositories window appears.

  4. Click Browse to locate your local Git repository.

    crs adding a local git repo
  5. In the Search results field, select the checkbox displaying the path to the .git file.
  6. Click Add.

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

crs local git repo

1.2.3. Cloning an existing Git repository

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

Procedure

  1. Start CodeReady Studio.
  2. Open Git Perspective.
  3. Click the Clone a Git Repository and add the clone to this view icon.

    crs git perspective clone a git repo

    The Clone Git Repository window appears.

    crs cloning a git repo
  4. Add the address for the source repository to the URI field.

    The Host and Repository path fields are populated automatically.

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

    crs verifying pah to repo
  9. Click Finish.

Your cloned repository is now listed in the Git Repositories view of CodeReady Studio.

crs cloned git repo

1.2.4. Adding a remote for the repository

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

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

Procedure

  1. Start CodeReady Studio.
  2. Open Git Perspective.
  3. Expand your repository.

    crs creating a remote
  4. Right-click Remotes Create Remote.

    The New Remote window appears.

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

    The Configure Push window appears.

    crs configure push window
  8. Click Change.

    The Select a URI window appears.

    crs select uri window
  9. Add the URI, username and password for the source repository.

    The Host and Repository path fields are populated automatically.

  10. Click Finish.
  11. Click Save.

Your newly added remote is now listed in the Git Repositories view in CodeReady Studio.

crs remote created

1.3. Managing branches in Git Perspective

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. Open Git Perspective.
  3. Expand your repository.
  4. Under branches Remote Tracking, right-click master Create Branch.

    crs create new branch

    The Create Branch window appears.

    crs create new branch window
  5. Click Select to pick the source of the new branch.
  6. Name your branch.
  7. Select the Configure upstream for push and pull and Checkout new branch check boxes.
  8. Select an option in the When pulling field.
  9. Click Finish.

Your newly added branch is now listed in the Git Repositories view under branches Local in CodeReady Studio.

crs new branch

1.3.2. Working in the branch

The following section describes how to open a built-in terminal in Git Perspective so you can work on the created branch.

Procedure

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

    The Launch Terminal window appears.

    crs launch terminal window
  4. Choose Local Terminal.
  5. Set Encoding to Default (ISO-8859-1).
  6. Click OK.

    The Terminal window now displays the command-line terminal.

    crs terminal

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

1.3.3. Updating your local repository

To avoid merge conflicts, update your local repository before merging your changes, especially when working in a shared repository.
To update your local repository, pull changes from the remote repository and merge them into your local repository.

Procedure

  1. Start CodeReady Studio.
  2. Open Git Perspective.
  3. Right-click your repository Pull.

    crs pull

    The Pull Results window appears.

    crs pull request
  4. Click Close.

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

1.4. Committing and pushing changes

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

Procedure

  1. Start CodeReady Studio.
  2. Open Git Perspective.
  3. Right-click your repository Commit.

    crs commit

    The Git Staging view appears.

    crs git perspective stage files to commit
  4. Select the changes you want to stage.
  5. Click the Add selected files to the index icon to stage the changes.
  6. Add a commit message to the Commit Message field.

    Author and Committer fields are populated automatically.

  7. Click Commit to commit your changes, or Commit and Push 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, your access username, and password for the repository.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.