Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

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