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.
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.
Using the CLI
Using the CLI
-
To create a new branch, use the following command in your terminal:
git branch <new_branch_name>
-
To switch to the new branch, run:
git checkout <new_branch_name>
Using the IDE
- Locate the branch name in the bottom-left corner of your status bar.
- 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.
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
-
Add your changes to the staging area:
git add .
-
Commit the changes with a message:
git commit -m "<commit_message>"
Using the IDE
- Open the Source Control view from the Activity Bar.
- To stage changes, click the plus sign next to individual files or next to the Changes heading to stage all files at once.
- Type a commit message describing your changes in the provided text box.
- Click Commit to save these changes.
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.
Using the IDE
- In the Source Control view, locate and click the arrow icon next to the Commit option.
- From the dropdown menu, select Commit and Push to stage, commit, and immediately push your changes to the remote repository.
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.
Using the IDE
- Open the Source Control view from the Activity Bar.
- Click the pull icon at the top of the sidebar.
- Select Pull from the dropdown menu.
Creating a Pull Request (PR)
You can create a Pull Request (PR) using the CLI or your IDE.
Using the CLI
- Push your changes to the upstream branch:
git push origin <branch_name>
- Navigate to your Git provider (e.g., GitHub) to create the Pull Request.
Using the IDE
- Install the GitHub Pull Requests Extension in your IDE.
- Access your open issues and Pull Requests directly from the sidebar.
- Click the Pull Requests icon, fill in the required details, and submit your PR.
By following this guide, you can efficiently manage source control tasks within your Gitspaces, enhancing your workflow.