Skip to content

Add a way to sync remote origin with remote upstream #1160

Closed

Description

@goran-w

When working in a typical open-source workflow (for example when contributing to SourceGit on GitHub), there are often two remotes:

  • our own forked repo (origin)
  • the master-repo (upstream)

After a Fetch (from all remotes), the origin branches are often lagging behind the corresponding upstream branches. To sync an origin branch against its upstream, we can use Open In Browser in SourceGit (on the origin remote) and then (on the GitHub repo web page) select "Sync fork (origin) branch with upstream". However, it would be nice if this operation could be performed without leaving the SourceGit UI (at least when fast-forward is possible).

Possible (minimal/partial) implementation:

  • Right-clicking a remote branch origin/develop gives the option Fast-forward to upstream/develop (similar to how it works for local branches).
  • Other variants for syncing between two remote branches could be added later, but fast-forward is arguably the most common and trivial use-case.
  • At least initially, it could be assumed that the remote and upstream branch needs to have the same name in order to be synced?
  • To establish which remote is the upstream, we may need to split the Default Remote dropdown (in Repository Configure) into two separate ones: Default Remote Origin and Default Remote Upstream.
  • Alternatively, a sub-menu per remote could be used (similar to the one used per branch/tag when right-clicking in the log-graph) to enable syncing between arbitrary pairs of remotes (which may not be as "safe" as requiring configuration of a dedicated Origin + Upstream).

Activity

  1. love-linger commented on Apr 7, 2025

    @love-linger
    Collaborator

    In fact, you can create a Custom Action for this purpose, such as:

    git fetch -a
    git checkout <forked_branch>
    git merge <upstream_remote>/<branch> <forked_branch>
  2. goran-w commented on Apr 7, 2025

    @goran-w
    ContributorAuthor

    To match what the GitHub feature does, there should be one more command, after the ones you listed above (I guess?) :

    git push <origin_remote> <forked_branch>
  3. goran-w commented on Apr 7, 2025

    @goran-w
    ContributorAuthor

    Hmm, I suppose what I actually want is to Sync a remote fork branch with the GitHub CLI. This would help "save time and avoid switching context", but would be specific for GitHub and not general for Git.

    I suppose I could setup a Custom Action to run the command gh repo sync <owner>/<fork-repo> --branch <branch-name>.

    Things could be somewhat more automated after setting gh repo set-default <owner>/<fork-repo> once in the local repo. Then that default repo is used by default for some gh commands, and we can query the default repo using gh repo set-default --view.

  4. self-assigned this
    on Apr 8, 2025
  5. love-linger commented on Apr 8, 2025

    @love-linger
    Collaborator

    All interfaces to third-party git code hosting services will not be directly integrated in the software. It is recommended that users use Custom Actions.

  6. goran-w commented on Apr 8, 2025

    @goran-w
    ContributorAuthor

    Fair enough! For reference, I ended upp adding a couple of nifty Custom Actions to my sourcegit fork clone (for the develop and master branches, respectively), like this :

    Name: Sync GH fork's branch: develop
    Scope: Repository
    Executable file: gh
    Arguments: repo sync goran-w/sourcegit -b develop
    ✔ Wait for action exit

    Works like a charm! (Could be further enhanced by using a script, which does a git fetch origin afterwards.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

not-plannedIt's not planned in the future

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions