Skip to content

Commit 7efa299

Browse files
jaimergpmgornyh-vetinari
authored
How to: keep your fork in sync (#2663)
Co-authored-by: Michał Górny <[email protected]> Co-authored-by: h-vetinari <[email protected]>
1 parent a010f60 commit 7efa299

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

docs/_sidebar_diataxis.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
"type": "link",
6969
"label": "Rerender a feedstock",
7070
"href": "/docs/maintainer/updating_pkgs/#rerendering-feedstocks"
71+
},
72+
{
73+
"type": "doc",
74+
"label": "Keep your fork in sync",
75+
"id": "how-to/basics/fork-sync"
7176
}
7277
]
7378
},

docs/how-to/basics/fork-sync.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
tags: [how-to, basic]
3+
---
4+
5+
# How to keep your fork in sync
6+
7+
The `conda-forge` workflow assumes that contributors will _always_ open their pull requests from their feedstock fork. Follow these best practices to make sure your branches are always up-to-date.
8+
9+
## Terminology
10+
11+
Given a `conda-forge/package-feedstock` repository, Github allows you to create a copy on your account, called _fork_. You have full rights over your forked repository, and it should be the place where you experiment with new branches and changes.
12+
13+
The original repository is usually referred to as `upstream`.
14+
15+
## How to fork a feedstock
16+
17+
Forks are easily created from the Github UI:
18+
19+
1. Go to the conda-forge feedstock
20+
2. Click on the Fork button in the top right corner
21+
3. Select on which account you want to create the fork. Choose your personal account, not an organization.
22+
23+
## How to keep your fork in sync
24+
25+
Never push directly to your fork's `main` branch. This branch should always be identical to upstream. This way your new branches will never start with merge conflicts.
26+
27+
You can sync your fork `main` with upstream's via the Github UI. Look for an option named "Sync". Then, in your local copy of the forked repository, run: `git checkout main && git pull`.
28+
29+
Locally, you can follow these steps:
30+
31+
1. If not available on disk yet, clone your fork and change into its directory.
32+
2. Change the branch to `main`: `git checkout main`.
33+
3. Pull from upstream: `git pull --ff-only upstream main`.
34+
35+
If this results in a "not possible to fast-forward" error, check [the section below](#how-to-resolve-conflicts-in-main).
36+
37+
Once `main` is synced, you can create a new branch with `git checkout -b new-branch-name`.
38+
39+
## How to resolve conflicts in `main`
40+
41+
When pulling from `upstream`, you might run into merge conflicts or "not possible to fast-forward" errors. This can happen if you pushed to your fork's `main` branch instead of creating a new one.
42+
43+
If you don't care about your local changes, you can simply do `git checkout main && git reset --hard upstream/main`.
44+
If you want to save your changes but still make your fork's `main` identical to `upstream`'s:
45+
46+
1. If you just tried to `pull` and got merge conflicts, abort with `git merge --abort`. Otherwise, check the info in `git status` and make sure you are you are in the `main` branch: `git checkout main`.
47+
2. Park your local `main` in separate branch, as a backup: `git checkout -b parked-changes`.
48+
3. Ensure your remotes are fresh: `git fetch upstream`.
49+
4. Go back to `main` and reset it to `upstream`'s: `git checkout main && git reset --hard upstream/main`.
50+
51+
Alternatively, create a backup of your `main` branch with `git checkout main && git checkout -b parked-changes`
52+
and then try to pull with a rebase strategy with `git rebase -i upstream/main`.
53+
The idea here is to replay the commits you want to keep on top of the `upstream/main` branch, while dropping
54+
those that have become obsolete (or are otherwise conflict-prone, like rerender commits).
55+
[Gitlab's docs on `git rebase`](https://docs.gitlab.com/topics/git/git_rebase/) contain more details on this type of workflow.

0 commit comments

Comments
 (0)