Triangular workflows are a common pattern in Git-based development, especially for open-source contributions. This process typically involves forking a repository, cloning the fork, making changes, pushing those changes to the fork, and then creating a pull request to the original upstream repository. While effective, managing remotes in this setup can sometimes be cumbersome. The GitHub CLI now introduces a feature that significantly streamlines this workflow.
When a repository is forked and then cloned, Git automatically sets the origin remote to point to the user’s fork. To interact with the original repository (the “upstream”), developers usually need to manually add it as a new remote, often named upstream. This means that commands like git push or git pull must explicitly specify which remote to use (e.g., git push upstream main or git pull upstream main). This extra step can interrupt the flow and lead to errors if the wrong remote is targeted.

The GitHub CLI Solution: gh repo set-default
The GitHub CLI addresses this challenge with a new command: gh repo set-default. This command allows a developer to designate a default remote for a repository, which can be the upstream repository. Once set, standard Git commands like git push and git pull will automatically interact with this default remote, simplifying the entire process.
To set the default remote, navigate to the cloned repository directory and use the command:
gh repo set-default <owner/repo>
For example, if contributing to github/cli, the command would be gh repo set-default github/cli.
To view the currently set default remote:
gh repo set-default –view
To clear the default remote setting:
gh repo set-default –unset
How It Enhances Your Workflow
With a default upstream remote configured, pushing changes directly to the upstream repository becomes as simple as git push. Similarly, pulling the latest updates from the upstream repository can be done with a straightforward git pull. This eliminates the need to constantly remember and type upstream or the full remote name, making the development cycle smoother and more intuitive. This feature is particularly beneficial for contributors who frequently interact with the upstream repository.
Practical Applications
This functionality is highly valuable in several scenarios:
- Open Source Contributions: Developers contributing to open-source projects can more easily synchronize their local work with the main project, reducing friction in the contribution process.
- Internal Team Development: Teams that utilize a fork-based model for feature isolation or experimental branches can leverage this to simplify merging changes back into the main development line.
Conclusion
The gh repo set-default command in the GitHub CLI represents a significant improvement for anyone working with triangular Git workflows. By simplifying remote management, it enhances the developer experience, allowing for more efficient and less error-prone interactions with upstream repositories.

