Skip to content

Commit 89db04a

Browse files
authored
Merge pull request #1736 from Kobzol/fork-instructions
Update instructions for renaming rust-lang/rust default branch
2 parents 13dff99 + 23779cc commit 89db04a

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

content/inside-rust/renaming-the-default-branch-of-rust-lang-rust.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,50 @@ We will be renaming the default branch of the [rust-lang/rust repository](https:
1313

1414
If you maintain a tool that currently assumes the default branch of `rust-lang/rust` is named `master`, using `HEAD` instead will work both before and after the rename.
1515

16-
After the rename, contributors will need to run the following commands in their local checkout of the repository, assuming that your upstream remote is called `origin`:
16+
After the rename, contributors will need to run a few git commands in their local checkout of the repository to update. Note that the specific commands that should be executed might differ based on the way you use git and how your local checkout is configured. We provide a guide below that we think should work for most use-cases, but your mileage may vary.
17+
18+
Please try to follow the guide step-by-step, and if you run into any problems, feel free to ask in this [Zulip channel][infra-help-zulip].
19+
20+
## Renaming your fork's default branch
21+
22+
If you have a fork of the `rust-lang/rust` repository on GitHub, you should first update its default branch name before continuing. If you do not rename it and later run `git checkout master`, git will create a `master` branch based on your fork's outdated `master` branch, which can be confusing. Some of the following git commands in this post might also not work as expected.
23+
24+
Here is how you can update your fork's default branch:
25+
26+
1) Go to `https://github.com/<your-username>/rust/settings`
27+
2) Find the default branch section, click on the "Rename branch" button (pencil icon) and rename the branch to `main`.
28+
29+
## Updating your local git checkout
30+
31+
Execute the following git commands in your local checkout of the `rust` repository.
32+
33+
Note that the instructions below make two assumptions:
34+
- You have a git remote called `upstream` that points to the `rust-lang/rust` repository and a remote called `origin` that points to your `<username>/rust` fork. Please update the commands accordingly if you use a different setup.
35+
- You can find out which remotes you have configured using the `git remote -v` command.
36+
- Your local `master` branch tracks the default branch of your *fork*, not the default branch of the *upstream* `rust-lang/rust` repository. If that is not the case, execute the commented `git branch` command instead.
37+
- You can find which remote your local `master` branch tracks by using `git branch -vv --contains master` (the tracked branch should be shown in square brackets).
1738

1839
```bash
19-
git branch -m master main
40+
# Update the local branch name
41+
git branch --move master main
42+
43+
# Update local references to your <username>/rust fork
2044
git fetch origin
21-
git branch -u origin/main main
22-
git remote set-head origin -a
45+
git branch --set-upstream-to=origin/main main # If your main branch tracks your fork
46+
git remote set-head origin --auto
2347

24-
# optional
48+
# Update local references relevant to the upstream rust-lang/rust repository
49+
git fetch upstream
50+
#git branch --set-upstream-to=upstream/main main # If your main branch tracks the upstream repo
51+
git remote set-head upstream --auto
52+
53+
# Remove old branch names (optional, but recommended)
2554
git remote prune origin
55+
git remote prune upstream
2656
```
2757

28-
If you have a fork of the `rust-lang/rust` repository on GitHub and would like to rename your default branch to match, you can follow [GitHub's instructions][github-how-to-rename].
29-
30-
**We recommend renaming the default branch of your fork.** If you do not rename it and later run `git checkout master`, git will create a`master` branch based on your fork's outdated `master` branch. This behavior can be confusing.
31-
3258
[github-change]: https://github.blog/changelog/2020-10-01-the-default-branch-for-newly-created-repositories-is-now-main/
3359

3460
[github-tooling]: https://github.com/github/renaming
3561

36-
[github-how-to-rename]: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-branches-in-your-repository/changing-the-default-branch
62+
[infra-help-zulip]: (https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra/topic/Help.20with.20updating.20rust-lang.2Frust.20default.20branch/with/554127642)

0 commit comments

Comments
 (0)