Skip to main content

Using Source Control in your Gitpaces

This guide walks you through using source control in your Gitspaces, allowing you to perform all necessary Git actions directly within your Gitspace.

info

You can also monitor and track all changes made in your Gitspaces directly through the Harness UI. Learn more about tracking Gitspace changes in the documentation.

Pre-Requisite

Ensure you have created a Gitspace using the Harness UI and verify that it is running and in an active state.

Creating (Switching) a New Branch

In your Gitspace, you can create a new branch or switch between existing branches. The current branch you're working on is displayed in the bottom-left corner.

branch-1

Using the CLI

Using the CLI

  1. To create a new branch, use the following command in your terminal:
    git branch <new_branch_name>

  2. To switch to the new branch, run:
    git checkout <new_branch_name>

branch-2

Using the IDE

  1. Locate the branch name in the bottom-left corner of your status bar.
branch-1
  1. Click on it to open a dropdown menu where you can:
    • Create a new branch by entering its details.
    • Select and switch to an existing branch.
branch-3 branch-4

Commiting Changes to the Remote Repository

After making changes to your source code, you need to add and commit them to the remote repository.

Using the CLI

  1. Add your changes to the staging area:
    git add .

  2. Commit the changes with a message:
    git commit -m "<commit_message>"

commit-1

Using the IDE

  1. Open the Source Control view from the Activity Bar.
  2. To stage changes, click the plus sign next to individual files or next to the Changes heading to stage all files at once.
commit-2
  1. Type a commit message describing your changes in the provided text box.
  2. Click Commit to save these changes.
commit-3

Pushing Changes to the Remote Repository

Push your commits to the remote repository to make your changes available.

Using the CLI

Use the following command to push commits:
git push

If prompted to set an upstream branch, this associates your local branch with a branch on the remote repository.

push-1

Using the IDE

  1. In the Source Control view, locate and click the arrow icon next to the Commit option.
  2. From the dropdown menu, select Commit and Push to stage, commit, and immediately push your changes to the remote repository.
push-2

Pulling Changes from the Remote Repository

Sync your local repository with the latest changes from the remote repository.

Using the CLI

To pull changes from the remote repository, use:
git pull

This downloads and integrates remote updates into your local repository.

pull-1

Using the IDE

  1. Open the Source Control view from the Activity Bar.
  2. Click the pull icon at the top of the sidebar.
  3. Select Pull from the dropdown menu.
pull-2

Creating a Pull Request (PR)

You can create a Pull Request (PR) using the CLI or your IDE.

Using the CLI

  1. Push your changes to the upstream branch:
    git push origin <branch_name>
pr-2
  1. Navigate to your Git provider (e.g., GitHub) to create the Pull Request.
pr-1

Using the IDE

  1. Install the GitHub Pull Requests Extension in your IDE.
  2. Access your open issues and Pull Requests directly from the sidebar.
  3. Click the Pull Requests icon, fill in the required details, and submit your PR.
pr-3 pr-4

By following this guide, you can efficiently manage source control tasks within your Gitspaces, enhancing your workflow.