doc/user/project/repository/forking_workflow.md
{{< details >}}
{{< /details >}}
A fork is a personal copy of another project, created in the namespace of your choice. Your fork contains a copy of the upstream project's repository and some project settings, but not project content like issues, merge requests, or wiki pages. You can create merge requests from your fork to target the upstream project. Individual commits can also be cherry-picked from your fork into the upstream project.
If you have write access to the original project, you don't need a fork. Instead, use branches to manage your work. If you don't have write access to a project you want to contribute to, fork it. Make your changes in your fork, then submit them through a merge request to the upstream project.
To create a confidential merge request, use a personal fork of a public project.
[!note] If the upstream project is archived, the fork relationship is automatically removed. Merge requests that were closed due to a broken fork relationship are not reopened if the fork relationship is later restored.
For more information, see archive a project.
{{< history >}}
{{< /history >}}
To fork an existing project in GitLab:
--single-branch and --no-tags
Git options.GitLab creates your fork, redirects you to the new fork's page, and logs the fork's creation in the audit log.
If you intend to contribute changes upstream frequently, consider setting a default target for your fork.
A fork can fall out of sync with its upstream project, and require an update:
To sync your fork with its upstream project, update it from the GitLab UI or the command line. GitLab Premium and Ultimate tiers can also automate updates by configuring forks as pull mirrors of the upstream project.
{{< history >}}
synchronize_fork removed.{{< /history >}}
When you update a fork from the UI, the following repository protection settings on the fork are bypassed:
This behavior prevents synchronization failures when the upstream project and fork have different protection configurations. The synchronization process pulls changes from the upstream repository and applies them directly to the fork.
Prerequisites:
To update your fork from the GitLab UI:
In the top bar, select Search or go to.
Select View all my projects.
Select the fork you want to update.
Below the dropdown list for branch name, find the Forked from ({{< icon name="fork" >}}) information box to determine if your fork is ahead, behind, or both. In this example, the fork is behind the upstream project:
If your fork is ahead of the upstream project, select Create merge request to propose adding your fork's changes to the upstream project.
If your fork is behind the upstream project, select Update fork to pull changes from the upstream repository.
If your fork is ahead and behind the upstream project, you can update from the UI only if GitLab detects no merge conflicts:
You can also update your fork from the command line.
Prerequisites:
To update your fork from the command line, follow the instructions in use Git to update a fork.
{{< details >}}
{{< /details >}}
A fork can be configured as a mirror of the upstream project if all these conditions are met:
main).main.Repository mirroring keeps your fork synced with the original project.
This method updates your fork once per hour, with no manual git pull required.
For instructions, see configure pull mirroring.
[!warning] With mirroring, before approving a merge request, you are asked to sync. You should automate it.
When you are ready to send your code back to the upstream project, create a new merge request as described in when you work in a fork. When successfully merged, your changes are added to the upstream repository.
After your merge request is merged upstream, the branch in your fork is not automatically considered Merged for bulk deletion purposes. The branch is only considered merged if your fork's default branch contains those changes. To mark these branches as merged in your fork, update your fork to sync with the upstream project.
Removing a fork relationship unlinks your fork from its upstream project. Your fork then becomes an independent project.
Prerequisites:
[!warning] If you remove a fork relationship, you can't send new merge requests to the source. Any existing open merge requests from the fork to the source are also closed. If anyone has forked your project, their fork also loses the relationship. To restore the fork relationship, use the Project forks API.
To remove a fork relationship:
GitLab logs the unlink operation in the audit log. When you unlink a fork that uses a hashed storage pool to share objects with another repository:
Deleting a fork permanently removes the project and all its contents, including the fork relationship. This action is the same as deleting any other project.
To delete a fork, see delete a project.
Your fork uses a deduplication strategy to reduce the storage space it needs. Your fork can access the object pool connected to the source project.
For more information and to check the storage use, see view project fork storage usage.
An error occurred while forking the project. Please try againThis error can be due to a mismatch in instance runner settings between the forked project and the new namespace. For more information, see using instance runners in forked projects.
If removing the fork through the UI or API is not working, you can attempt the fork relationship removal in a Rails console session:
p = Project.find_by_full_path('<project_path>')
u = User.find_by_username('<username>')
Projects::UnlinkForkService.new(p, u).execute
User is not allowed to import projectsWhen forking a project using a service account, you might receive an error that states:
{"message":["Namespace is not valid","User is not allowed to import projects"]}
This issue occurs because service accounts are bot users and cannot fork projects to their personal namespace, even if their project limit has been increased.
When using a service account to fork a project, the workaround is to specify a target group namespace
using either namespace_id or namespace_path in the Project forks API.
The service account must be a member of the target group with the Developer, Maintainer, or Owner role.