I have forked a repository that is constantly updated by the creator. How do I go about updating my forked copy so that I have the most up-to-date files?
you can do that in two ways. Both of them expect that you never work on the default branch (main/master, check your project settings) of your fork, but only create change commits in feature and fix branches.
Settings > Repository > Mirroring repositories.
- Add the upstream URL
- Mirror direction:
Only mirror protected branches(optional)
This feature is available in the Premium tier: Pull from a remote repository | GitLab
Add a secondary remote called
git remote add upstream https://...
Fetch the remote and then pull its changes into your local default branch, for example
git checkout main git fetch upstream git pull upstream main
Last, push to your own remote
origin to keep the forked repo in sync.
git push origin main
Based on the default main branch, you can continue with creating branches, e.g.
git checkout -b feature/....
You could also write a script for that, e.g. when you’re syncing between different Git servers.
One liner script in your forked clone:
git remote add upstream https://gitlab.com/upstream_user_group/project.git || true && git fetch upstream && git checkout main && git pull upstream main && git push origin main
Thank you for that detailed instruction. With your first option (GitLab Repository Mirror), I only have the option for PUSH for Mirror Direction. Any idea why this might be?
maybe the form needs a refresh, I’ve found it a bit wonky when adding a new item. Or the URL you’re providing above is the same as the current repository. Can you share a screenshot?
Look valid to me. Maybe try hitting refresh once, then copy the URL again. I had some issues with the different form states until it allowed me to change the mirror direction. Though I was using gitlab.com, not sure whether this is an advanced option only applicable in EE.
Seems the issue is that I’m on a hosted GitLab through my company. When I try this on gitlab.com, I have the Push/Pull option, but when I’m on my company’s site, I only have Pull.
Ah, I see. Didn’t look into the specific docs section where this feature is marked as a paid tier feature.
In that case (assuming you’re using the free tier), I’d suggest going the manual scripted way with adding that to a cronjob somewhere. Or you’ll migrate to Premium/Ultimate
worked liked a charm
Thank you, you saved my day! :)))
A post was split to a new topic: Problem with repository mirroring for forks
I’ve linked the feature request in GitLab in the tutorial above. Offer to fetch and merge new upstream contents when fork is behind (#330243) · Issues · GitLab.org / GitLab · GitLab - please upvote and/or dive into contributing it in case you want to see it happen
To: method1 : strage it only let me push this way, the select is frozen
Thanks, I thought I had added the feature availability note. I have edited my response from before joining GitLab, and added that
pull is available in the Premium tier, more details in Pull from a remote repository | GitLab
This post was flagged by the community and is temporarily hidden.