|
2 | 2 | title: "Catching up with reality"
|
3 | 3 | ---
|
4 | 4 |
|
5 |
| -If it's taking a while to develop your feature, and you want to catch up with what's in the current Home Assistant `dev` branch, you can use `git rebase`. This will pull the latest Home Assistant changes locally, rewind your commits, bring in the latest changes from Home Assistant, and replay all of your commits on top. |
| 5 | +If it's taking a while to develop your feature, and you want to catch up with what's in the current Home Assistant `dev` branch, you can either use `git merge` or `git rebase`. |
| 6 | +Bellow you can find instructions on how to do it using `git merge`. This will pull the latest Home Assistant changes locally, and merge them into your branch by creating a merge commit. |
6 | 7 |
|
7 |
| -:::tip |
8 |
| -If you use the workflow below, it is important that you force push the update as described. Git might prompt you to do `git pull` first. Do **NOT** do that! It would mess up your commit history. |
9 |
| -::: |
10 |
| - |
11 |
| -You should have added an additional `remote` after you clone your fork. If you did not, do it now before proceeding. |
| 8 | +You should have added an additional `remote` after you clone your fork. If you did not, do it now before proceeding: |
12 | 9 |
|
13 | 10 | ```shell
|
14 | 11 | git remote add upstream https://github.com/home-assistant/core.git
|
15 | 12 | ```
|
16 | 13 |
|
17 | 14 | ```shell
|
18 | 15 | # Run this from your feature branch
|
19 |
| -git fetch upstream dev # to pull the latest changes into a local dev branch |
20 |
| -git rebase upstream/dev # to put those changes into your feature branch before your changes |
| 16 | +git fetch upstream dev # to fetch the latest changes into a local dev branch |
| 17 | +git merge upstream/dev # to put those changes into your feature branch before your changes |
21 | 18 | ```
|
22 | 19 |
|
23 |
| -If rebase detects conflicts, repeat this process until all changes have been resolved: |
| 20 | +If git detects any conflicts do the following to solve them: |
24 | 21 |
|
25 |
| -1. `git status` shows you the file with the conflict; edit the file and resolve the lines between `<<<< | >>>>` |
| 22 | +1. Use `git status` to see the file with the conflict; edit the file and resolve the lines between `<<<< | >>>>` |
26 | 23 | 2. Add the modified file: `git add <file>` or `git add .`
|
27 |
| -3. Continue rebase: `git rebase --continue` |
28 |
| -4. Repeat until you've resolved all conflicts |
| 24 | +3. Finish the merge by commiting it (you can leave the default merge commit message unchanged): `git commit` |
29 | 25 |
|
30 |
| -After rebasing your branch, you will have rewritten history relative to your GitHub fork's branch. When you go to push you will see an error that your history has diverged from the original branch. In order to get your GitHub fork up-to-date with your local branch, you will need to force push, using the following command: |
| 26 | +Finally, just push your changes as normal: |
31 | 27 |
|
32 | 28 | ```shell
|
33 | 29 | # Run this from your feature branch
|
34 |
| -git push origin --force-with-lease |
| 30 | +git push |
35 | 31 | ```
|
36 | 32 |
|
37 |
| -If that command fails, it means that new work was pushed to the branch from either you or another contributor since your last rebase. |
38 |
| -You will have to start over the git fetch and rebase process described above, or if you are really confident those changes are not needed, just overwrite them: |
| 33 | +If that command fails, it means that new work was pushed to the branch from either you or another contributor since your last update. In that case, just pull them into your local branch, solve any conflicts and push everything again: |
39 | 34 |
|
40 | 35 | ```shell
|
41 |
| -# Run this from your feature branch, overwriting any changes in the remote branch |
42 |
| -git push origin --force |
| 36 | +# Run this from your feature branch |
| 37 | +git pull --no-rebase |
| 38 | +git push |
43 | 39 | ```
|
44 | 40 |
|
| 41 | + |
45 | 42 | Other workflows are covered in detail in the [Github documentation](https://docs.github.com/get-started/quickstart/fork-a-repo).
|
0 commit comments