- 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-syncgh fork-sync <options>To see the list of available options, run:
gh fork-sync --helpIf run without arguments it will sync local main branch with the upstream main branch and push the changes to the origin.
gh fork-syncIt will execute the following commands:
git remote add upstream <upstream-repository-url>
git fetch upstream
git merge upstream/main
git push origin HEAD:mainTip
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=featureIt will execute the following commands:
git remote add upstream <upstream-repository-url>
git fetch upstream
git merge upstream/main
git push origin HEAD:featureIn 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=featureYou can force push the changes to the origin repository by using --force option.
gh fork-sync --forceIt will execute the following commands:
git remote add upstream <upstream-repository-url>
git fetch upstream
git merge upstream/main
git push -f origin HEAD:mainYou can use --rebase option to rebase the changes instead of merging them.
gh fork-sync --rebaseIt will execute the following commands:
git remote add upstream <upstream-repository-url>
git fetch upstream
git rebase upstream/main
git push origin HEAD:mainUsually you have to use --rebase option with --force option.
gh fork-sync --rebase --forceIt will execute the following commands:
git remote add upstream <upstream-repository-url>
git fetch upstream
git rebase upstream/main
git push -f origin HEAD:mainYou can see the commands that would be executed by using --dry-run option.
gh fork-sync --dry-runIt 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 buildThen 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