Skip to content

Simple GitHub CLI extension to keep your fork up-to-date

License

Notifications You must be signed in to change notification settings

ankddev/gh-fork-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gh-fork-sync

GitHub CLI extension to sync your fork with the upstream repository

Preview

Features

  • Sync your fork with the upstream repository
  • Rebase instead of merge
  • Set upstream and origin branch names
  • Force push the changes
  • Preview the commands without executing them

Installation

Firstly, install the GitHub CLI

Then, install the extension:

gh extension install ankddev/gh-fork-sync

Usage

gh fork-sync <options>

To see the list of available options, run:

gh fork-sync --help

Basic usage

If run without arguments it will sync local main branch with the upstream main branch and push the changes to the origin.

gh fork-sync

It will execute the following commands:

git remote add upstream <upstream-repository-url>
git fetch upstream
git merge upstream/main
git push origin HEAD:main

Tip

You can see what commands will be executed by running gh fork-sync with --dry-run option.

Specifying branch names

You can specify the branch names for the upstream and origin repositories.

gh fork-sync --upstream-branch=main --origin-branch=feature

It will execute the following commands:

git remote add upstream <upstream-repository-url>
git fetch upstream
git merge upstream/main
git push origin HEAD:feature

In this example you can omit --upstream-branch option, because it will use the default branch name from the upstream repository.

gh fork-sync --origin-branch=feature

Force push

You can force push the changes to the origin repository by using --force option.

gh fork-sync --force

It will execute the following commands:

git remote add upstream <upstream-repository-url>
git fetch upstream
git merge upstream/main
git push -f origin HEAD:main

Rebase

You can use --rebase option to rebase the changes instead of merging them.

gh fork-sync --rebase

It will execute the following commands:

git remote add upstream <upstream-repository-url>
git fetch upstream
git rebase upstream/main
git push origin HEAD:main

Usually you have to use --rebase option with --force option.

gh fork-sync --rebase --force

It will execute the following commands:

git remote add upstream <upstream-repository-url>
git fetch upstream
git rebase upstream/main
git push -f origin HEAD:main

Dry run

You can see the commands that would be executed by using --dry-run option.

gh fork-sync --dry-run

It will print the commands that would be executed and exit.

Contributing

Contributions are welcome! Please feel free to submit a PR.

Build instructions

Clone the repository and run go build in the root directory.

git clone https://github.com/ankddev/gh-fork-sync.git
cd gh-fork-sync
go build

Then you can install the extension by running gh extension install . in the root directory.

gh extension install .

Testing

You can test the extension by running go test in the root directory.

go test