Forks are repositories that start as copies of another repository, called the upstream repository. A fork has its own settings and permissions but stays connected to the upstream repository.
When you view a forked repository on GitHub, the upstream repository is indicated below the name of the fork.
What makes forks distinct from branches
A branch is part of one repository. A fork is a separate repository with its own settings and collaboration space.
Each fork can have its own:
- Branches
- Members and discussions
- Issues and pull requests
- Actions and projects
- Tags, labels, and wikis
Which repositories can be forked?
可将任何公共存储库分叉到:
- 你的个人帐户
- 你有权在其中创建存储库的组织
如果你有权访问专用存储库,并且所有者允许分叉,则可以将存储库分叉到:
- 你的个人帐户
- 你有权在其中创建存储库的 GitHub Team 上的组织
不能使用 GitHub Free 将专用存储库分支创建到组织。 有关 GitHub Team 和 GitHub Free 的详细信息,请参阅“GitHub的计划”。
Repository, organization, and enterprise policies can limit whether repositories can be forked and where forks can be created. For private repositories, access to forks also depends on repository visibility, organization membership, and administrator settings.
If you're a member of an 具有托管用户的企业, additional restrictions apply to the repositories you can fork. See 关于 Enterprise Managed Users in the GitHub Enterprise Cloud documentation.
See 管理组织的复刻政策.
Visibility of forks
A fork's visibility is tied to the upstream repository's repository network. Public repository forks are public, and private repository forks are private. You cannot change the visibility of a fork by itself.
All repositories in a repository network share the same visibility setting. A repository network includes the upstream repository, its forks, and forks of those forks. See 了解仓库之间的连接.
Deleting a repository or changing its visibility can affect the network. If you delete a fork, code contributions from that fork can remain accessible to the repository network.
What happens to forks when a repository is deleted or changes visibility
警告
Visibility changes can separate forks into new repository networks so that existing fork owners can keep working without unexpected loss of access.
| Action | Effect on forks |
|---|---|
| A private repository is deleted | Its private forks are also deleted. |
| A public repository is deleted | An active public fork becomes the new upstream repository for the network. |
| A public repository is made private | Its public forks stay public in a separate network. |
| A private repository is made public | Private forks stay private but disconnect into separate private networks. |
Changing a public repository to private can also affect stars, watchers, dependency graph, Dependabot alerts, and code scanning availability. Review repository visibility settings carefully before changing them.
Permissions of forks
专用分支继承上游存储库的权限结构。 这有助于私有仓库的所有者保持对其代码的控制。 例如,如果上游仓库是私有的,并授予团队读/写访问权限,则同一团队对该私有上游仓库的任何复刻拥有读/写权限。 专用分支仅继承团队权限(而不是个人权限)。
注意
更改组织的基本权限时,不会对专用分支的权限进行自动更新。 有关详细信息,请参阅“为组织设置基本权限”。
Public forks do not inherit the permissions structure of the upstream repository. Fork owners control access to their forks, but repository networks still share Git data. Commits pushed to any repository in a network can be accessible from other repositories in that network, including the upstream repository.
When you fork a public repository to your personal account, you can allow maintainers of the upstream repository to push to your pull request branch. This can help maintainers update your branch, run tests, or resolve small issues before merging. You cannot give push permissions to a fork owned by an organization. See Allowing changes to a pull request branch created from a fork.
Push rulesets for forked repositories
推送规则适用于存储库的整个分支网络,以确保存储库的每个入口点均受到保护。 例如,如果将已启用推送规则集的存储库创建为分支,则相同的推送规则集也适用于已创建分支的存储库。
对于已创建分支的存储库,只有对推送规则具有旁路权限的人员是根存储库中具有旁路权限的人员。
See 关于规则集.
Important security considerations
Forks are powerful collaboration tools, but they can expose code and history in ways that are easy to overlook.
- Forks have their own permissions separate from the upstream repository.
- Owners of an upstream repository can read all forks in the repository network.
- Organization owners may have administrative access to forks created in personal namespaces.
- Removing someone's access to the upstream repository does not always delete forks in other organizations.
- Commits can remain accessible in the repository network even after a fork is deleted.
Before allowing forks for sensitive work, review the permissions and visibility model for your repository or organization.
Forks within an organization
Forks within the same organization copy collaborator and team settings from the upstream repository. The organization controls permissions for these forks, and existing visible teams may keep access.
Forks within an enterprise
Internal repositories support a single level of forking. You cannot fork a private fork of an internal repository. This keeps access and management simpler for repositories that are visible across an enterprise.