Skip to content

Commit

Permalink
Use origin consistently and add an example of rebasing over the wro…
Browse files Browse the repository at this point in the history
…ng remote
  • Loading branch information
jyn514 committed Dec 29, 2022
1 parent ba1db24 commit 586474f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
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.

0 comments on commit 586474f

Please sign in to comment.