aboutsummaryrefslogtreecommitdiff
path: root/docs/newbs_git_resynchronize_a_branch.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/newbs_git_resynchronize_a_branch.md')
-rw-r--r--docs/newbs_git_resynchronize_a_branch.md71
1 files changed, 71 insertions, 0 deletions
diff --git a/docs/newbs_git_resynchronize_a_branch.md b/docs/newbs_git_resynchronize_a_branch.md
new file mode 100644
index 000000000..2e6b26e09
--- /dev/null
+++ b/docs/newbs_git_resynchronize_a_branch.md
@@ -0,0 +1,71 @@
1# Resynchronizing an Out-of-Sync Git Branch
2
3Suppose you have committed to your `master` branch, and now need to update your QMK repository. You could `git pull` QMK's `master` branch into your own, but GitHub will tell you that your commit is a number of commits ahead of `qmk:master`, which can create issues if you want to make a pull request to QMK.
4
5?> This document builds upon the concepts detailed in [Your Fork's Master: Update Often, Commit Never](newbs_git_using_your_master_branch.md). If you are not familiar with that document, please read it first, then return here.
6
7## Backing Up the Changes on Your Own Master Branch (Optional)
8
9No one wants to lose work if it can be helped. If you want to save the changes you've already made to your `master` branch, the simplest way to do so is to simply create a duplicate of your "dirty" `master` branch:
10
11```sh
12git branch old_master master
13```
14
15Now you have a branch named `old_master` that is a duplicate of your `master` branch.
16
17## Resynchronizing Your Branch
18
19Now it's time to resynchronize your `master` branch. For this step, you'll want to have QMK's repository configured as a remote in Git. To check your configured remotes, run `git remote -v`, which should return something similar to:
20
21```sh
22QMKuser ~/qmk_firmware (master)
23$ git remote -v
24origin https://github.com/<your_username>/qmk_firmware.git (fetch)
25origin https://github.com/<your_username>/qmk_firmware.git (push)
26upstream https://github.com/qmk/qmk_firmware.git (fetch)
27upstream https://github.com/qmk/qmk_firmware.git (push)
28```
29
30If you only see one fork referenced:
31
32```sh
33QMKuser ~/qmk_firmware (master)
34$ git remote -v
35origin https://github.com/qmk/qmk_firmware.git (fetch)
36origin https://github.com/qmk/qmk_firmware.git (push)
37```
38
39add a new remote with:
40
41```sh
42git remote add upstream https://github.com/qmk/qmk_firmware.git
43```
44
45Then, redirect the `origin` remote to your own fork with:
46
47```sh
48git remote set-url origin https://github.com/<your_username>/qmk_firmware.git
49```
50
51Now that you have both remotes configured, you need to update the references for the upstream repository, which is QMK's, by running:
52
53```sh
54git fetch upstream
55```
56
57At this point, resynchronize your branch to QMK's by running:
58
59```sh
60git reset --hard upstream/master
61```
62
63These steps will update the repository on your computer, but your GitHub fork will still be out of sync. To resynchronize your fork on GitHub, you need to push to your fork, instructing Git to override any remote changes that are not reflected in your local repository. To do this, run:
64
65```sh
66git push --force-with-lease
67```
68
69!> **DO NOT** run `git push --force-with-lease` on a fork to which other users post commits. This will erase their commits.
70
71Now your GitHub fork, your local files, and QMK's repository are all the same. From here you can make further needed changes ([use a branch!](newbs_git_using_your_master_branch.md#making-changes)) and post them as normal.