You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
3.0 KiB

  1. # Resynchronizing an Out-of-Sync Git Branch
  2. Suppose 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 branch is a number of commits ahead of `qmk:master`, which can create issues if you want to make a pull request to QMK.
  3. ?> 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.
  4. ## Backing Up the Changes on Your Own Master Branch (Optional)
  5. No 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:
  6. ```
  7. git branch old_master master
  8. ```
  9. Now you have a branch named `old_master` that is a duplicate of your `master` branch.
  10. ## Resynchronizing Your Branch
  11. Now 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:
  12. ```
  13. QMKuser ~/qmk_firmware (master)
  14. $ git remote -v
  15. origin https://github.com/<your_username>/qmk_firmware.git (fetch)
  16. origin https://github.com/<your_username>/qmk_firmware.git (push)
  17. upstream https://github.com/qmk/qmk_firmware.git (fetch)
  18. upstream https://github.com/qmk/qmk_firmware.git (push)
  19. ```
  20. If you only see one fork referenced:
  21. ```
  22. QMKuser ~/qmk_firmware (master)
  23. $ git remote -v
  24. origin https://github.com/qmk/qmk_firmware.git (fetch)
  25. origin https://github.com/qmk/qmk_firmware.git (push)
  26. ```
  27. add a new remote with:
  28. ```
  29. git remote add upstream https://github.com/qmk/qmk_firmware.git
  30. ```
  31. Then, redirect the `origin` remote to your own fork with:
  32. ```
  33. git remote set-url origin https://github.com/<your_username>/qmk_firmware.git
  34. ```
  35. Now that you have both remotes configured, you need to update the references for the upstream repository, which is QMK's, by running:
  36. ```
  37. git fetch --recurse-submodules upstream
  38. ```
  39. At this point, resynchronize your branch to QMK's by running:
  40. ```
  41. git reset --recurse-submodules --hard upstream/master
  42. ```
  43. These 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:
  44. ```
  45. git push --recurse-submodules=on-demand --force-with-lease
  46. ```
  47. !> **DO NOT** run `git push --recurse-submodules=on-demand --force-with-lease` on a fork to which other users post commits. This will erase their commits.
  48. Now 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.