Skip to content

Add more rebasing help #1536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use origin consistently and add an example of rebasing over the wro…
…ng remote
  • Loading branch information
jyn514 committed Dec 29, 2022
commit 2117a9c17409a9f275a4fca7568c934e78154249
37 changes: 27 additions & 10 deletions src/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Here are some common issues you might run into:

Git has two ways to update your branch with the newest changes: merging and rebasing.
Rust [uses rebasing][no-merge-policy]. If you make a merge commit, it's not too hard to fix:
`git rebase -i origin/master`.
`git rebase -i upstream/master`.

See [Rebasing][#rebasing] for more about rebasing.

Expand All @@ -114,16 +114,16 @@ it will say something like this:

```
$ git remote -v
origin https://github.com//rust-lang/rust (fetch)
origin https://github.com//rust-lang/rust (push)
personal https://github.com/jyn514/rust (fetch)
personal https://github.com/jyn514/rust (push)
origin git@github.com:jyn514/rust.git (fetch)
origin git@github.com:jyn514/rust.git (push)
upstream https://github.com/rust-lang/rust (fetch)
upstream https://github.com/rust-lang/rust (fetch)
```

If you renamed your fork, you can change the URL like this:

```console
git remote set-url personal <URL>
git remote set-url origin <URL>
```

where the `<URL>` is your new fork.
Expand Down Expand Up @@ -174,6 +174,24 @@ and just want to get a clean copy of the repository back, you can use `git reset
git reset --hard master
```

### Git is trying to rebase commits I didn't write?

If you see many commits in your rebase list, or merge commits, or commits by other people that you
didn't write, it likely means you're trying to rebase over the wrong branch. For example, you may
have a `rust-lang/rust` remote `upstream`, but ran `git rebase origin/master` instead of `git rebase
upstream/master`. The fix is to abort the rebase and use the correct branch instead:

```
git rebase --abort
git rebase -i upstream/master
```

<details><summary>Click here to see an example of rebasing over the wrong branch</summary>

![Interactive rebase over the wrong branch](img/other-peoples-commits.png)

</details>

### Quick note about submodules

When updating your local repository with `git pull`, you may notice that sometimes
Expand Down Expand Up @@ -308,17 +326,16 @@ and rebase them:
```
git checkout master
git pull upstream master --ff-only # to make certain there are no merge commits
git checkout feature_branch
git rebase master
git push --force-with-lease (set origin to be the same as local)
git rebase master feature_branch
git push --force-with-lease # (set origin to be the same as local)
```

To avoid merges as per the [No-Merge Policy](#no-merge-policy), you may want to use
`git config pull.ff only` (this will apply the config only to the local repo)
to ensure that Git doesn't create merge commits when `git pull`ing, without
needing to pass `--ff-only` or `--rebase` every time.

You can also `git push --force-with-lease` from master to keep your origin's master in sync with
You can also `git push --force-with-lease` from master to keep your fork's master in sync with
upstream.

## Advanced Rebasing
Expand Down
Binary file added src/img/other-peoples-commits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.