Skip to content

Commit 586474f

Browse files
committed
Use origin consistently and add an example of rebasing over the wrong remote
1 parent ba1db24 commit 586474f

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/git.md

+27-10
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Here are some common issues you might run into:
103103

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

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

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

115115
```
116116
$ git remote -v
117-
origin https://github.com//rust-lang/rust (fetch)
118-
origin https://github.com//rust-lang/rust (push)
119-
personal https://github.com/jyn514/rust (fetch)
120-
personal https://github.com/jyn514/rust (push)
117+
origin git@github.com:jyn514/rust.git (fetch)
118+
origin git@github.com:jyn514/rust.git (push)
119+
upstream https://github.com/rust-lang/rust (fetch)
120+
upstream https://github.com/rust-lang/rust (fetch)
121121
```
122122

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

125125
```console
126-
git remote set-url personal <URL>
126+
git remote set-url origin <URL>
127127
```
128128

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

177+
### Git is trying to rebase commits I didn't write?
178+
179+
If you see many commits in your rebase list, or merge commits, or commits by other people that you
180+
didn't write, it likely means you're trying to rebase over the wrong branch. For example, you may
181+
have a `rust-lang/rust` remote `upstream`, but ran `git rebase origin/master` instead of `git rebase
182+
upstream/master`. The fix is to abort the rebase and use the correct branch instead:
183+
184+
```
185+
git rebase --abort
186+
git rebase -i upstream/master
187+
```
188+
189+
<details><summary>Click here to see an example of rebasing over the wrong branch</summary>
190+
191+
![Interactive rebase over the wrong branch](img/other-peoples-commits.png)
192+
193+
</details>
194+
177195
### Quick note about submodules
178196

179197
When updating your local repository with `git pull`, you may notice that sometimes
@@ -308,17 +326,16 @@ and rebase them:
308326
```
309327
git checkout master
310328
git pull upstream master --ff-only # to make certain there are no merge commits
311-
git checkout feature_branch
312-
git rebase master
313-
git push --force-with-lease (set origin to be the same as local)
329+
git rebase master feature_branch
330+
git push --force-with-lease # (set origin to be the same as local)
314331
```
315332

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

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

324341
## Advanced Rebasing

src/img/other-peoples-commits.png

294 KB
Loading

0 commit comments

Comments
 (0)