- 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
Firstly, install the GitHub CLI
Then, install the extension:
gh extension install ankddev/gh-fork-sync
gh fork-sync <options>
To see the list of available options, run:
gh fork-sync --help
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.
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
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
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
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.
Contributions are welcome! Please feel free to submit a PR.
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 .
You can test the extension by running go test
in the root directory.
go test