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