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.

219 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, issues, 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 its **description**. Nothing else comes with it: no issues or
31pull requests, settings, rulesets, secrets, variables, webhooks,
32environments, deployments or releases. The fork starts with its own
33defaults, 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
43Deployments stay off until the fork's own project is set up.
44
45### Who can see a fork
46
47A fork is exactly as visible as its parent: a public repository's forks
48are public, a private repository's are private. Within that, the fork's
49own workspace and roles decide who can read and write it.
50
51A fork cannot be made public or private on its own. To change who can see
52it, [detach it](/guides/forking-repositories/#detach-a-fork) first.
53
54### Forking a private repository
55
56Anyone who can read a public repository may fork it. A private repository
57is forked only when its admins allow it under **Settings → Repository →
58Forking**, and only by people who can read it. A private fork stays tied to
59that access: when whoever made it can no longer read the parent (they left
60its workspace, say), their fork is deleted, and its workspace's owners can
61restore it for 30 days. A fork made with a workspace's own token is kept.
62
63### What a fork costs
64
65A fork's full size counts toward the
66[private repository storage](/guides/usage-and-billing/#private-repository-storage)
67of the workspace it goes in, from the moment it is made, however much of it
68is the same as its parent. Its workflows' minutes and its other usage are
69its own workspace's too.
70
71A free workspace cannot take a private fork that would carry its private
72repositories past 1 GB. Public forks, as all public repositories, are not
73charged for storage.
74
75### Keeping up with the parent
76
77A fork does not move when its parent does. **Syncing** a branch brings in
78the commits the parent's branch of the same name has (the parent's default
79branch, 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
87See [Sync a fork](/guides/forking-repositories/#sync-a-fork).
88
89### Proposing changes back
90
91A pull request from a fork is opened on the parent, from a branch of the
92fork, and is reviewed, checked and merged there under the parent's rules.
93Its checks are the **parent's** workflows, run under the parent's settings,
94and the parent's [approval policy](/guides/actions/#pull-requests-from-outside)
95decides whether they wait for someone to approve them. Whoever opened the
96pull request, its runs get none of the parent's secrets and no token that
97can write to it, since anyone who can push to the fork can change the code
98they 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
109A detached fork keeps its code, settings and pull requests, and its
110workflows and issues stay off unless someone had turned them on. It can no longer be
111synced, and it cannot be attached again.
112
113## Working copies for pull requests
114
115A pull request can come from a branch of the repository. But a coding
116agent's pull request comes from a **working copy**: a separate repository
117that starts as a copy of yours and belongs to that pull request alone. This
118part 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
134To push to a branch, an agent needs write access to the repository. That
135access also covers `main` and every other branch, unless protection rules
136are written and kept correct for each one.
137
138An agent working in a working copy holds a credential for that copy. It can
139rewrite history, force-push, or delete everything it has, and `main` and
140every other pull request are untouched. The limit is structural: it does
141not depend on a rule being configured correctly.
142
143#### A thousand pull requests leave the repository unchanged
144
145Every clone and fetch begins with the server listing the repository's refs.
146A branch per pull request means a repository with thousands of refs, each
147listed to every client on every fetch, and each needing cleanup once the
148work is merged or closed.
149
150Working copies add nothing to the repository's branches. A day after a pull
151request merges or closes, its working copy is removed, and only its head is
152kept in the repository, as `refs/pull/<pull request id>/head`, which clones
153and fetches do not download. The repository's branches stay the handful
154that describe the project.
155
156#### Each pull request has its own capacity
157
158Storage and request limits apply per repository. A hundred agents pushing to
159one repository share one budget and slow each other down. A hundred working
160copies have a hundred budgets.
161
162#### Working copies are cheap here
163
164Making a working copy takes one call and is ready in about the time a
165branch would be, even for a large repository. Its storage is counted with
166the repository it belongs to, and it is gone a day after its pull request
167closes.
168
169#### Anyone's agent can contribute
170
171Opening a pull request on a public repository does not need any access to
172it. The author pushes to the pull request's working copy, and the
173repository's workspace decides whether it merges. This is how open source
174has always taken contributions from strangers, applied to agents.
175
176### What working copies cost
177
178They 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
193When you are a person working on your own repository, or a small team that
194already has write access. Nothing about isolation or scale is at stake, and
195a branch is the tool you already know.
196
197Push the branch, open **Pull requests**, choose **New pull request** and
198pick it. Or from the API, send `branch` when creating the pull request:
199
200```sh
201git push origin my-change
202curl -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
207A branch can have one open pull request at a time. Pushing to the branch
208updates it.
209
210Without write access, [fork the repository](/guides/forking-repositories/)
211and open the pull request from a branch of your fork.
212
213### How this adds up
214
215One person, one change: a branch is right, and g1t keeps it. Someone
216outside who wants to keep their own line of work: a fork. Hundreds of
217agents, many of them wrong, some of them not yours: the repository should
218not carry their weight or trust them with its history. Working copies give
219each of them room to work and give `main` one narrow, checked way in.