Skip to content

Instantly share code, notes, and snippets.

@syhily
Last active November 14, 2021 08:27
Show Gist options
  • Save syhily/9444f8ef7c1cac0359f6be23cecfad14 to your computer and use it in GitHub Desktop.
Save syhily/9444f8ef7c1cac0359f6be23cecfad14 to your computer and use it in GitHub Desktop.
Update git fork with tags and selected branches.
# Repo: apache/flink
# Fork: streamnative/flink
# Prepare the working enviroment
## Clone the forked repository
git clone git@github.com:streamnative/flink.git
## Add the original repository as the upstream git remote
git remote add upstream git@github.com:apache/flink.git
# Main logic
## Fetch the origin and upstream (with tags)
git fetch origin -p
git fetch upstream -p --tags
## Sync master & release-* branch
for branch in $(git ls-remote --heads upstream|sed 's#^.*refs/heads/##'|egrep -i "^(release-|master)"); do
echo "Sync the branch: ${branch}"
git push origin refs/remotes/upstream/${branch}:refs/heads/${branch}
done
## Update all the tags
git push --tags
## Update current working branch
git pull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment