| 1 | --- |
| 2 | title: Forks and working copies |
| 3 | description: What a fork is, who can see it and what it costs; why a pull request on g1t gets a working copy of its own, and when a branch is the better choice. |
| 4 | --- |
| 5 | |
| 6 | g1t has two kinds of copy of a repository, made for different reasons: |
| 7 | |
| 8 | - A **fork** is a repository someone copied into their own workspace. It |
| 9 | belongs to them, lives at its own address, and remembers the repository |
| 10 | it came from, its **parent**, so it can be kept up to date and propose |
| 11 | changes back. |
| 12 | - A **working copy** is the separate repository a pull request gets when it |
| 13 | is not opened from a branch: an agent's pull request, usually. It belongs |
| 14 | to that one pull request, is hidden from listings, and is removed a day |
| 15 | after the pull request closes. |
| 16 | |
| 17 | This page explains both. To fork a repository, see |
| 18 | [Forking a repository](/guides/forking-repositories/). |
| 19 | |
| 20 | ## Forks |
| 21 | |
| 22 | A fork is an ordinary repository of the workspace it is in. It has its own |
| 23 | access, settings, rules, issues, pull requests, workflows and project. What |
| 24 | it shares with its parent is where it came from: it can be synced from the |
| 25 | parent and can open pull requests into it. |
| 26 | |
| 27 | ### What a fork starts with |
| 28 | |
| 29 | Forking copies the parent's **code** (its default branch, or every branch |
| 30 | and tag), and the fork's project starts with the **description** of the |
| 31 | parent's project. Nothing else comes with it: no issues or |
| 32 | pull requests, settings, rulesets, secrets, variables, webhooks, |
| 33 | environments, deployments or releases. The fork starts with its own |
| 34 | defaults, and with two things off: |
| 35 | |
| 36 | - **Workflows.** A fork runs none of the workflows it copied until someone |
| 37 | who manages its settings turns them on in **Settings → Actions**. Code you |
| 38 | copied should not start running on your account, with your secrets and |
| 39 | your minutes, just because you copied it. |
| 40 | - **Issues.** A fork usually exists to change code and propose it back; |
| 41 | the conversation stays on the parent. Turn them on in the fork's settings |
| 42 | if it becomes a project of its own. |
| 43 | |
| 44 | Deployments stay off until the fork's own project is set up. |
| 45 | |
| 46 | ### Who can see a fork |
| 47 | |
| 48 | A fork is exactly as visible as its parent: a public repository's forks |
| 49 | are public, a private repository's are private. Within that, the fork's |
| 50 | own workspace and roles decide who can read and write it. |
| 51 | |
| 52 | A fork cannot be made public or private on its own. To change who can see |
| 53 | it, [detach it](/guides/forking-repositories/#detach-a-fork) first. |
| 54 | |
| 55 | ### Forking a private repository |
| 56 | |
| 57 | Anyone who can read a public repository may fork it. A private repository |
| 58 | is forked only when its admins allow it under **Settings → Repository → |
| 59 | Forking**, and only by people who can read it. A private fork stays tied to |
| 60 | that access: when whoever made it can no longer read the parent (they left |
| 61 | its workspace, say), their fork is deleted, and its workspace's owners can |
| 62 | restore it for 30 days. A fork made with a workspace's own token is kept. |
| 63 | |
| 64 | ### What a fork costs |
| 65 | |
| 66 | A fork's full size counts toward the |
| 67 | [private repository storage](/guides/usage-and-billing/#private-repository-storage) |
| 68 | of the workspace it goes in, from the moment it is made, however much of it |
| 69 | is the same as its parent. Its workflows' minutes and its other usage are |
| 70 | its own workspace's too. |
| 71 | |
| 72 | A free workspace cannot take a private fork that would carry its private |
| 73 | repositories past 1 GB. Public forks, as all public repositories, are not |
| 74 | charged for storage. |
| 75 | |
| 76 | ### Keeping up with the parent |
| 77 | |
| 78 | A fork does not move when its parent does. **Syncing** a branch brings in |
| 79 | the commits the parent's branch of the same name has (the parent's default |
| 80 | branch, for the fork's default branch): |
| 81 | |
| 82 | - a branch that is only behind moves forward to match; |
| 83 | - a branch with commits of its own gets a merge commit, when the two sides' |
| 84 | changes do not clash: edits to the same file merge line by line; |
| 85 | - when both changed the same lines, nothing changes, and you are told which |
| 86 | files: merge them in a clone and push. |
| 87 | |
| 88 | See [Sync a fork](/guides/forking-repositories/#sync-a-fork). |
| 89 | |
| 90 | ### Proposing changes back |
| 91 | |
| 92 | A pull request from a fork is opened on the parent, from a branch of the |
| 93 | fork, and is reviewed, checked and merged there under the parent's rules. |
| 94 | Its checks are the **parent's** workflows, run under the parent's settings, |
| 95 | and the parent's [approval policy](/guides/actions/#pull-requests-from-outside) |
| 96 | decides whether they wait for someone to approve them. Whoever opened the |
| 97 | pull request, its runs get none of the parent's secrets and no token that |
| 98 | can write to it, since anyone who can push to the fork can change the code |
| 99 | they run. The fork's own settings do not change any of that. |
| 100 | |
| 101 | ### When the parent changes |
| 102 | |
| 103 | | The parent | Its forks | |
| 104 | | --- | --- | |
| 105 | | Is made public or private | Are detached: they become ordinary repositories, and keep the visibility they had. | |
| 106 | | Is deleted | Stay forks while it can be restored. When it is purged, they become forks of the repository it was forked from, or ordinary repositories if it was not a fork. | |
| 107 | | Is renamed or transferred | Follow it: they are forks of it at its new address. | |
| 108 | | Is archived | Stay forks; syncing from it still works. | |
| 109 | |
| 110 | A detached fork keeps its code, settings and pull requests, and its |
| 111 | workflows and issues stay off unless someone had turned them on. It can no longer be |
| 112 | synced, and it cannot be attached again. |
| 113 | |
| 114 | ## Working copies for pull requests |
| 115 | |
| 116 | A pull request can come from a branch of the repository. But a coding |
| 117 | agent's pull request comes from a **working copy**: a separate repository |
| 118 | that starts as a copy of yours and belongs to that pull request alone. This |
| 119 | part explains why, what it costs, and when to use which. |
| 120 | |
| 121 | ### The short version |
| 122 | |
| 123 | | | Working copy per pull request | Branch in the repository | |
| 124 | | --- | --- | --- | |
| 125 | | Built for | Coding agents, in any number | A person, or a few | |
| 126 | | What the worker can write to | Its own working copy, nothing else | The repository | |
| 127 | | Effect on the repository | None until something merges | A new ref for every piece of work | |
| 128 | | Sees `main` move | Only when it pulls | On the next fetch | |
| 129 | | Merging | Objects are copied in, then `main` moves | `main` moves | |
| 130 | |
| 131 | ### Why working copies, for agents |
| 132 | |
| 133 | #### An agent cannot damage what it cannot write to |
| 134 | |
| 135 | To push to a branch, an agent needs write access to the repository. That |
| 136 | access also covers `main` and every other branch, unless protection rules |
| 137 | are written and kept correct for each one. |
| 138 | |
| 139 | An agent working in a working copy holds a credential for that copy. It can |
| 140 | rewrite history, force-push, or delete everything it has, and `main` and |
| 141 | every other pull request are untouched. The limit is structural: it does |
| 142 | not depend on a rule being configured correctly. |
| 143 | |
| 144 | #### A thousand pull requests leave the repository unchanged |
| 145 | |
| 146 | Every clone and fetch begins with the server listing the repository's refs. |
| 147 | A branch per pull request means a repository with thousands of refs, each |
| 148 | listed to every client on every fetch, and each needing cleanup once the |
| 149 | work is merged or closed. |
| 150 | |
| 151 | Working copies add nothing to the repository's branches. A day after a pull |
| 152 | request merges or closes, its working copy is removed, and only its head is |
| 153 | kept in the repository, as `refs/pull/<pull request id>/head`, which clones |
| 154 | and fetches do not download. The repository's branches stay the handful |
| 155 | that describe the project. |
| 156 | |
| 157 | #### Each pull request has its own capacity |
| 158 | |
| 159 | Storage and request limits apply per repository. A hundred agents pushing to |
| 160 | one repository share one budget and slow each other down. A hundred working |
| 161 | copies have a hundred budgets. |
| 162 | |
| 163 | #### Working copies are cheap here |
| 164 | |
| 165 | Making a working copy takes one call and is ready in about the time a |
| 166 | branch would be, even for a large repository. Its storage is counted with |
| 167 | the repository it belongs to, and it is gone a day after its pull request |
| 168 | closes. |
| 169 | |
| 170 | #### Anyone's agent can contribute |
| 171 | |
| 172 | Opening a pull request on a public repository does not need any access to |
| 173 | it. The author pushes to the pull request's working copy, and the |
| 174 | repository's workspace decides whether it merges. This is how open source |
| 175 | has always taken contributions from strangers, applied to agents. |
| 176 | |
| 177 | ### What working copies cost |
| 178 | |
| 179 | They are not free of trade-offs. |
| 180 | |
| 181 | - **Falling behind is quieter.** A branch sees new commits on `main` at the |
| 182 | next fetch. A working copy has to pull from the original repository, |
| 183 | which is a second remote. The merge box says when a pull request is |
| 184 | behind, merging brings it up to date by itself unless the branch must be |
| 185 | up to date first, and its author can |
| 186 | [update the branch](/guides/pull-requests/#keeping-it-up-to-date) from |
| 187 | the merge box; but a clone of the working copy only has the new commits |
| 188 | once its author pulls them. |
| 189 | - **Merging does more work.** Merging from a working copy copies the new |
| 190 | objects into the repository before moving `main`. From a branch they are |
| 191 | already there. |
| 192 | - **The remote is a different URL.** Engineers used to pushing a branch to |
| 193 | `origin` need to push to the pull request's working copy instead. |
| 194 | |
| 195 | ### When a branch is the better choice |
| 196 | |
| 197 | When you are a person working on your own repository, or a small team that |
| 198 | already has write access. Nothing about isolation or scale is at stake, and |
| 199 | a branch is the tool you already know. |
| 200 | |
| 201 | Push the branch, open **Pull requests**, choose **New pull request** and |
| 202 | pick it. Or from the API, send `branch` when creating the pull request: |
| 203 | |
| 204 | ```sh |
| 205 | git push origin my-change |
| 206 | curl -X POST https://api.g1t.sh/repos/<workspace>/<repo>/pulls \ |
| 207 | -H "Authorization: Bearer $G1T_TOKEN" -H "Content-Type: application/json" \ |
| 208 | -d '{"branch": "my-change", "title": "My change", "issue": 12}' |
| 209 | ``` |
| 210 | |
| 211 | A branch can have one open pull request at a time. Pushing to the branch |
| 212 | updates it. |
| 213 | |
| 214 | Without write access, [fork the repository](/guides/forking-repositories/) |
| 215 | and open the pull request from a branch of your fork. |
| 216 | |
| 217 | ### How this adds up |
| 218 | |
| 219 | One person, one change: a branch is right, and g1t keeps it. Someone |
| 220 | outside who wants to keep their own line of work: a fork. Hundreds of |
| 221 | agents, many of them wrong, some of them not yours: the repository should |
| 222 | not carry their weight or trust them with its history. Working copies give |
| 223 | each of them room to work and give `main` one narrow, checked way in. |