Skip to content

Commit 072657e

Browse files
guswynnjyn514
authored andcommitted
Add a section on keeping things up to date in the git section
1 parent c8da5bf commit 072657e

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

src/about-this-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ There are six parts to this guide:
1010
useful no matter how you are contributing, about building, debugging,
1111
profiling, etc.
1212
2. [Contributing to `rustc`][p1-5]: Contains information that should be useful
13-
no matter how you are contributing, about procedures for contribution,
14-
stabilizing features, etc.
13+
no matter how you are contributing, about procedures for contribution, using git
14+
and Github, stabilizing features, etc.
1515
2. [High-Level Compiler Architecture][p2]: Discusses the high-level
1616
architecture of the compiler and stages of the compile process.
1717
3. [Source Code Representation][p3]: Describes the process of taking raw source code from the user and

src/contributing.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ Pull requests (or PRs for short) are the primary mechanism we use to change Rust
6464
GitHub itself has some [great documentation][about-pull-requests] on using the
6565
Pull Request feature. We use the "fork and pull" model [described here][development-models],
6666
where contributors push changes to their personal fork and create pull requests to
67-
bring those changes into the source repository.
67+
bring those changes into the source repository. We have more info about how to use git
68+
when contributing to Rust under [the git section](./git.md).
6869

6970
[about-pull-requests]: https://help.github.com/articles/about-pull-requests/
7071
[development-models]: https://help.github.com/articles/about-collaborative-development-models/

src/git.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,19 @@ git remote add upstream [email protected]:rust-lang/rust.git
4646

4747
if you're using SSH.
4848

49+
**NOTE:** This page is dedicated to workflows for `rust-lang/rust`, but will likely be
50+
useful when contributing to other repositories in the Rust project.
51+
52+
4953
## Standard Process
5054

5155
Below is the normal procedure that you're likely to use for most minor changes
5256
and PRs:
5357

5458
1. Ensure that you're making your changes on top of master:
5559
`git checkout master`.
56-
2. Get the latest changes from the Rust repo: `git pull upstream master`.
60+
2. Get the latest changes from the Rust repo: `git pull upstream master --ff-only`.
61+
(see [No-Merge Policy](#keeping-things-up-to-date) for more info about this).
5762
3. Make a new branch for your change: `git checkout -b issue-12345-fix`.
5863
4. Make some changes to the repo and test them.
5964
5. Stage your changes via `git add src/changed/file.rs src/another/change.rs`
@@ -62,8 +67,13 @@ and PRs:
6267
unintentionally commit changes that should not be committed, such as submodule
6368
updates. You can use `git status` to check if there are any files you forgot
6469
to stage.
65-
6. Push your changes to your fork: `git push --set-upstream origin issue-12345-fix`.
66-
7. [Open a PR][ghpullrequest] from your fork to rust-lang/rust's master branch.
70+
6. Push your changes to your fork: `git push --set-upstream origin issue-12345-fix`
71+
(After adding commits, you can use `git push` and after rebasing or
72+
pulling-and-rebasing, you can use `git push --force-with-lease`).
73+
7. If you end up needing to rebase and are hitting conflicts, see [Rebasing](#rebasing).
74+
8. If you want to track upstream while working on long-running feature/issue, see
75+
[Keeping things up to date](#keeping-things-up-to-date).
76+
9. [Open a PR][ghpullrequest] from your fork to `rust-lang/rust`'s master branch.
6777

6878
[ghpullrequest]: https://guides.github.com/activities/forking/#making-a-pull-request
6979

@@ -160,7 +170,7 @@ it's not anything you did wrong. There is a workaround at [#77620].
160170

161171
[#77620]: https://github.com/rust-lang/rust/issues/77620#issuecomment-705228229
162172

163-
## Conflicts
173+
## Rebasing and Conflicts
164174

165175
When you edit your code locally, you are making changes to the version of
166176
rust-lang/rust that existed when you created your feature branch. As such, when
@@ -236,6 +246,34 @@ The advice this gives is incorrect! Because of Rust's
236246
will not be allowed in the final PR, in addition to defeating the point of the
237247
rebase! Use `git push --force-with-lease` instead.
238248

249+
### Keeping things up to date
250+
251+
The above section on [Rebasing](#rebasing) is a specific
252+
guide on rebasing work and dealing with merge conflicts.
253+
Here is some general advice about how to keep your local repo
254+
up-to-date with upstream changes:
255+
256+
Using `git pull upstream master` while on your local master branch regularly
257+
will keep it up-to-date. You will also want to rebase your feature branches
258+
up-to-date as well. After pulling, you can checkout the feature branches
259+
and rebase them:
260+
261+
```
262+
git checkout master
263+
git pull upstream master --ff-only # to make certain there are no merge commits
264+
git checkout feature_branch
265+
git rebase master
266+
git push --force-with-lease (set origin to be the same as local)
267+
```
268+
269+
To avoid merges as per the [No-Merge Policy][#no-merge-policy], you may want to use
270+
`git config pull.ff only` (this will apply the config to the local repo).
271+
to avoid merge conflicts while pulling, without needing
272+
`--ff-only` or `--rebase` while `git pull`ing
273+
274+
You can also `git push --force-with-lease` from master to keep your origin's master in sync with
275+
upstream.
276+
239277
## Advanced Rebasing
240278

241279
If your branch contains multiple consecutive rewrites of the same code, or if
@@ -330,6 +368,7 @@ that merge commits in PRs are not accepted. As a result, if you are running
330368
course, this is not always true; if your merge will just be a fast-forward,
331369
like the merges that `git pull` usually performs, then no merge commit is
332370
created and you have nothing to worry about. Running `git config merge.ff only`
371+
(this will apply the config to the local repo).
333372
once will ensure that all the merges you perform are of this type, so that you
334373
cannot make a mistake.
335374

0 commit comments

Comments
 (0)