aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJames Young <18669334+noroadsleft@users.noreply.github.com>2019-12-02 18:47:02 -0800
committerGitHub <noreply@github.com>2019-12-02 18:47:02 -0800
commit3152bf572b702109b9b01757ffe900d7f4387faf (patch)
tree5cce85a831fc5c909a4d135099f6fc90c64d4b08 /docs
parent96d4ba84c245066ae0ccd0f8216d7f11f80e5d98 (diff)
downloadqmk_firmware-3152bf572b702109b9b01757ffe900d7f4387faf.tar.gz
qmk_firmware-3152bf572b702109b9b01757ffe900d7f4387faf.zip
[Docs] Restructure of Git Best Practices doc (#7231)
* Add "Resynchronizing an Out-of-Sync Git Branch" doc * Update (Git) Best Practices doc title and filename * Rename Branch Resync doc * fork Best Practices doc into multiple files * Add the doc list to Git Best Practices doc * Update sidebar * Update internal references * Update sidebar - add subsection * Update Your Fork's Master page title * title case on Git Best Practices main doc * ... and in the Resynchronizing a Branch doc * Please read Part 1 I worked really hard on this, okay? * Please use branches, too. * suggestions by mtei * change note about adding multiple files * note that the name given the remote repo is arbitrary * suggestions by fauxpark * Git Best Practices -> Best Git Practices Reads more naturally. * rephrase hint block regarding remote name * rework the resynchronization instructions per mtei * use hint boxes for reference to Part 1 doc I may be addicted to hint boxes. I'm sorry fauxpark. :cry: * add some clarity about the upstream repo * wordsmithing per mtei * restyle the shell code blocks Makes them more consistent to the other docs in this section.
Diffstat (limited to 'docs')
-rw-r--r--docs/_summary.md5
-rw-r--r--docs/newbs_best_practices.md163
-rw-r--r--docs/newbs_git_best_practices.md16
-rw-r--r--docs/newbs_git_resolving_merge_conflicts.md79
-rw-r--r--docs/newbs_git_resynchronize_a_branch.md71
-rw-r--r--docs/newbs_git_using_your_master_branch.md74
6 files changed, 244 insertions, 164 deletions
diff --git a/docs/_summary.md b/docs/_summary.md
index 409df6d18..b6ee4a923 100644
--- a/docs/_summary.md
+++ b/docs/_summary.md
@@ -3,7 +3,10 @@
3 * [Building Your First Firmware](newbs_building_firmware.md) 3 * [Building Your First Firmware](newbs_building_firmware.md)
4 * [Flashing Firmware](newbs_flashing.md) 4 * [Flashing Firmware](newbs_flashing.md)
5 * [Testing and Debugging](newbs_testing_debugging.md) 5 * [Testing and Debugging](newbs_testing_debugging.md)
6 * [Git Best Practices](newbs_best_practices.md) 6 * [Best Git Practices](newbs_git_best_practices.md)
7 * [Using Your Fork's Master](newbs_git_using_your_master_branch.md)
8 * [Resolving Merge Conflicts](newbs_git_resolving_merge_conflicts.md)
9 * [Resynchronizing a Branch](newbs_git_resynchronize_a_branch.md)
7 * [Learning Resources](newbs_learn_more_resources.md) 10 * [Learning Resources](newbs_learn_more_resources.md)
8 11
9* [QMK Basics](README.md) 12* [QMK Basics](README.md)
diff --git a/docs/newbs_best_practices.md b/docs/newbs_best_practices.md
deleted file mode 100644
index 2ea4cfc35..000000000
--- a/docs/newbs_best_practices.md
+++ /dev/null
@@ -1,163 +0,0 @@
1# Best Practices
2
3## Or, "How I Learned to Stop Worrying and Love Git."
4
5This document aims to instruct novices in the best ways to have a smooth experience in contributing to QMK. We will walk through the process of contributing to QMK, detailing some ways to make this task easier, and then later we'll break some things in order to teach you how to fix them.
6
7This document assumes a few things:
8
91. You have a GitHub account, and have [forked the qmk_firmware repository](getting_started_github.md) to your account.
102. You've [set up your build environment](newbs_getting_started.md#set-up-your-environment).
11
12
13## Your fork's master: Update Often, Commit Never
14
15It is highly recommended for QMK development, regardless of what is being done or where, to keep your `master` branch updated, but ***never*** commit to it. Instead, do all your changes in a development branch and issue pull requests from your branches when you're developing.
16
17To reduce the chances of merge conflicts &mdash; instances where two or more users have edited the same part of a file concurrently &mdash; keep your `master` branch relatively up-to-date, and start any new developments by creating a new branch.
18
19### Updating your master branch
20
21To keep your `master` branch updated, it is recommended to add the QMK Firmware repository ("repo") as a remote repository in git. To do this, open your Git command line interface and enter:
22
23```
24git remote add upstream https://github.com/qmk/qmk_firmware.git
25```
26
27To verify that the repository has been added, run `git remote -v`, which should return the following:
28
29```
30$ git remote -v
31origin https://github.com/<your_username>/qmk_firmware.git (fetch)
32origin https://github.com/<your_username>/qmk_firmware.git (push)
33upstream https://github.com/qmk/qmk_firmware.git (fetch)
34upstream https://github.com/qmk/qmk_firmware.git (push)
35```
36
37Now that this is done, you can check for updates to the repo by running `git fetch upstream`. This retrieves the branches and tags &mdash; collectively referred to as "refs" &mdash; from the QMK repo, which now has the nickname `upstream`. We can now compare the data on our fork `origin` to that held by QMK.
38
39To update your fork's master, run the following, hitting the Enter key after each line:
40
41```
42git checkout master
43git fetch upstream
44git pull upstream master
45git push origin master
46```
47
48This switches you to your `master` branch, retrieves the refs from the QMK repo, downloads the current QMK `master` branch to your computer, and then uploads it to your fork.
49
50### Making Changes
51
52To make changes, create a new branch by entering:
53
54```
55git checkout -b dev_branch
56git push --set-upstream origin dev_branch
57```
58
59This creates a new branch named `dev_branch`, checks it out, and then saves the new branch to your fork. The `--set-upstream` argument tells git to use your fork and the `dev_branch` branch every time you use `git push` or `git pull` from this branch. It only needs to be used on the first push; after that, you can safely use `git push` or `git pull`, without the rest of the arguments.
60
61!> With `git push`, you can use `-u` in place of `--set-upstream` &mdash; `-u` is an alias for `--set-upstream`.
62
63You can name your branch nearly anything you want, though it is recommended to name it something related to the changes you are going to make.
64
65By default `git checkout -b` will base your new branch on the branch that is checked out. You can base your new branch on an existing branch that is not checked out by adding the name of the existing branch to the command:
66
67```
68git checkout -b dev_branch master
69```
70
71Now that you have a development branch, open your text editor and make whatever changes you need to make. It is recommended to make many small commits to your branch; that way, any change that causes issues can be more easily traced and undone if needed. To make your changes, edit and save any files that need to be updated, add them to Git's *staging area*, and then commit them to your branch:
72
73```
74git add path/to/updated_file
75git commit -m "My commit message."
76```
77
78`git add` adds files that have been changed to Git's *staging area*, which is Git's "loading zone." This contains the changes that are going to be *committed* by `git commit`, which saves the changes to the repo. Use descriptive commit messages so you can know what was changed at a glance.
79
80!> If you've changed a lot of files, but all the files are part of the same change, you can use `git add .` to add all the changed files that are in your current directory, rather than having to add each file individually.
81
82### Publishing Your Changes
83
84The last step is to push your changes to your fork. To do this, enter `git push`. Git now publishes the current state of `dev_branch` to your fork.
85
86
87## Resolving Merge Conflicts
88
89Sometimes when your work in a branch takes a long time to complete, changes that have been made by others conflict with changes you have made to your branch when you open a pull request. This is called a *merge conflict*, and is what happens when multiple people edit the same parts of the same files.
90
91### Rebasing Your Changes
92
93A *rebase* is Git's way of taking changes that were applied at one point, reversing them, and then applying the same changes to another point. In the case of a merge conflict, you can rebase your branch to grab the changes that were made between when you created your branch and the present time.
94
95To start, run the following:
96
97```
98git fetch upstream
99git rev-list --left-right --count HEAD...upstream/master
100```
101
102The `git rev-list` command entered here returns the number of commits that differ between the current branch and QMK's master branch. We run `git fetch` first to make sure we have the refs that represent the current state of the upstream repo. The output of the `git rev-list` command entered returns two numbers:
103
104```
105$ git rev-list --left-right --count HEAD...upstream/master
1067 35
107```
108
109The first number represents the number of commits on the current branch since it was created, and the second number is the number of commits made to `upstream/master` since the current branch was created, and thus, the changes that are not recorded in the current branch.
110
111Now that the current states of both the current branch and the upstream repo are known, we can start a rebase operation:
112
113```
114git rebase upstream/master
115```
116
117This tells Git to undo the commits on the current branch, and then reapply them against QMK's master branch.
118
119```
120$ git rebase upstream/master
121First, rewinding head to replay your work on top of it...
122Applying: Commit #1
123Using index info to reconstruct a base tree...
124M conflicting_file_1.txt
125Falling back to patching base and 3-way merge...
126Auto-merging conflicting_file_1.txt
127CONFLICT (content): Merge conflict in conflicting_file_1.txt
128error: Failed to merge in the changes.
129hint: Use 'git am --show-current-patch' to see the failed patch
130Patch failed at 0001 Commit #1
131
132Resolve all conflicts manually, mark them as resolved with
133"git add/rm <conflicted_files>", then run "git rebase --continue".
134You can instead skip this commit: run "git rebase --skip".
135To abort and get back to the state before "git rebase", run "git rebase --abort".
136```
137
138This tells us that we have a merge conflict, and gives the name of the file with the conflict. Open the conflicting file in your text editor, and somewhere in the file, you'll find something like this:
139
140```
141<<<<<<< HEAD
142<p>For help with any issues, email us at support@webhost.us.</p>
143=======
144<p>Need help? Email support@webhost.us.</p>
145>>>>>>> Commit #1
146```
147
148The line `<<<<<<< HEAD` marks the beginning of a merge conflict, and the `>>>>>>> Commit #1` line marks the end, with the conflicting sections separated by `=======`. The part on the `HEAD` side is from the QMK master version of the file, and the part marked with the commit message is from the current branch and commit.
149
150Because Git tracks *changes to files* rather than the contents of the files directly, if Git can't find the text that was in the file previous to the commit that was made, it won't know how to edit the file. Re-editing the file will solve the conflict. Make your changes, and then save the file.
151
152```
153<p>Need help? Email support@webhost.us.</p>
154```
155
156Now run:
157
158```
159git add conflicting_file_1.txt
160git rebase --continue
161```
162
163Git logs the changes to the conflicting file, and continues applying the commits from our branch until it reaches the end.
diff --git a/docs/newbs_git_best_practices.md b/docs/newbs_git_best_practices.md
new file mode 100644
index 000000000..c0cb3a294
--- /dev/null
+++ b/docs/newbs_git_best_practices.md
@@ -0,0 +1,16 @@
1# Best Git Practices for Working with QMK
2
3## Or, "How I Learned to Stop Worrying and Love Git."
4
5This section aims to instruct novices in the best ways to have a smooth experience in contributing to QMK. We will walk through the process of contributing to QMK, detailing some ways to make this task easier, and then later we'll break some things in order to teach you how to fix them.
6
7This section assumes a few things:
8
91. You have a GitHub account, and have [forked the qmk_firmware repository](getting_started_github.md) to your account.
102. You've set up both [your build environment](newbs_getting_started.md#set-up-your-environment) and [QMK](newbs_getting_started.md#set-up-qmk).
11
12---
13
14- Part 1: [Your Fork's Master: Update Often, Commit Never](newbs_git_using_your_master_branch.md)
15- Part 2: [Resolving Merge Conflicts](newbs_git_resolving_merge_conflicts.md)
16- Part 3: [Resynchronizing an Out-of-Sync Git Branch](newbs_git_resynchronize_a_branch.md)
diff --git a/docs/newbs_git_resolving_merge_conflicts.md b/docs/newbs_git_resolving_merge_conflicts.md
new file mode 100644
index 000000000..467c13abb
--- /dev/null
+++ b/docs/newbs_git_resolving_merge_conflicts.md
@@ -0,0 +1,79 @@
1# Resolving Merge Conflicts
2
3Sometimes when your work in a branch takes a long time to complete, changes that have been made by others conflict with changes you have made to your branch when you open a pull request. This is called a *merge conflict*, and is what happens when multiple people edit the same parts of the same files.
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## Rebasing Your Changes
8
9A *rebase* is Git's way of taking changes that were applied at one point in the commit history, reversing them, and then applying the same changes at another point. In the case of a merge conflict, you can rebase your branch to grab the changes that were made between when you created your branch and the present time.
10
11To start, run the following:
12
13```
14git fetch upstream
15git rev-list --left-right --count HEAD...upstream/master
16```
17
18The `git rev-list` command entered here returns the number of commits that differ between the current branch and QMK's master branch. We run `git fetch` first to make sure we have the refs that represent the current state of the upstream repo. The output of the `git rev-list` command entered returns two numbers:
19
20```
21$ git rev-list --left-right --count HEAD...upstream/master
227 35
23```
24
25The first number represents the number of commits on the current branch since it was created, and the second number is the number of commits made to `upstream/master` since the current branch was created, and thus, the changes that are not recorded in the current branch.
26
27Now that the current states of both the current branch and the upstream repo are known, we can start a rebase operation:
28
29```
30git rebase upstream/master
31```
32
33This tells Git to undo the commits on the current branch, and then reapply them against QMK's master branch.
34
35```
36$ git rebase upstream/master
37First, rewinding head to replay your work on top of it...
38Applying: Commit #1
39Using index info to reconstruct a base tree...
40M conflicting_file_1.txt
41Falling back to patching base and 3-way merge...
42Auto-merging conflicting_file_1.txt
43CONFLICT (content): Merge conflict in conflicting_file_1.txt
44error: Failed to merge in the changes.
45hint: Use 'git am --show-current-patch' to see the failed patch
46Patch failed at 0001 Commit #1
47
48Resolve all conflicts manually, mark them as resolved with
49"git add/rm <conflicted_files>", then run "git rebase --continue".
50You can instead skip this commit: run "git rebase --skip".
51To abort and get back to the state before "git rebase", run "git rebase --abort".
52```
53
54This tells us that we have a merge conflict, and gives the name of the file with the conflict. Open the conflicting file in your text editor, and somewhere in the file, you'll find something like this:
55
56```
57<<<<<<< HEAD
58<p>For help with any issues, email us at support@webhost.us.</p>
59=======
60<p>Need help? Email support@webhost.us.</p>
61>>>>>>> Commit #1
62```
63
64The line `<<<<<<< HEAD` marks the beginning of a merge conflict, and the `>>>>>>> Commit #1` line marks the end, with the conflicting sections separated by `=======`. The part on the `HEAD` side is from the QMK master version of the file, and the part marked with the commit message is from the current branch and commit.
65
66Because Git tracks *changes to files* rather than the contents of the files directly, if Git can't find the text that was in the file previous to the commit that was made, it won't know how to edit the file. Re-editing the file will solve the conflict. Make your changes, and then save the file.
67
68```
69<p>Need help? Email support@webhost.us.</p>
70```
71
72Now run:
73
74```
75git add conflicting_file_1.txt
76git rebase --continue
77```
78
79Git logs the changes to the conflicting file, and continues applying the commits from our branch until it reaches the end.
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.
diff --git a/docs/newbs_git_using_your_master_branch.md b/docs/newbs_git_using_your_master_branch.md
new file mode 100644
index 000000000..2032b83b2
--- /dev/null
+++ b/docs/newbs_git_using_your_master_branch.md
@@ -0,0 +1,74 @@
1# Your Fork's Master: Update Often, Commit Never
2
3It is highly recommended for QMK development, regardless of what is being done or where, to keep your `master` branch updated, but ***never*** commit to it. Instead, do all your changes in a development branch and issue pull requests from your branches when you're developing.
4
5To reduce the chances of merge conflicts &mdash; instances where two or more users have edited the same part of a file concurrently &mdash; keep your `master` branch relatively up-to-date, and start any new developments by creating a new branch.
6
7## Updating your master branch
8
9To keep your `master` branch updated, it is recommended to add the QMK Firmware repository ("repo") as a remote repository in git. To do this, open your Git command line interface and enter:
10
11```
12git remote add upstream https://github.com/qmk/qmk_firmware.git
13```
14
15?> The name `upstream` is arbitrary, but a common convention; you can give the QMK remote any name that suits you. Git's `remote` command uses the syntax `git remote add <name> <url>`, `<name>` being shorthand for the remote repo. This name can be used with many Git commands, including but not limited to `fetch`, `pull` and `push`, to specify the remote repo on which to act.
16
17To verify that the repository has been added, run `git remote -v`, which should return the following:
18
19```
20$ git remote -v
21origin https://github.com/<your_username>/qmk_firmware.git (fetch)
22origin https://github.com/<your_username>/qmk_firmware.git (push)
23upstream https://github.com/qmk/qmk_firmware.git (fetch)
24upstream https://github.com/qmk/qmk_firmware.git (push)
25```
26
27Now that this is done, you can check for updates to the repo by running `git fetch upstream`. This retrieves the branches and tags &mdash; collectively referred to as "refs" &mdash; from the QMK repo, which now has the nickname `upstream`. We can now compare the data on our fork `origin` to that held by QMK.
28
29To update your fork's master, run the following, hitting the Enter key after each line:
30
31```
32git checkout master
33git fetch upstream
34git pull upstream master
35git push origin master
36```
37
38This switches you to your `master` branch, retrieves the refs from the QMK repo, downloads the current QMK `master` branch to your computer, and then uploads it to your fork.
39
40## Making Changes
41
42To make changes, create a new branch by entering:
43
44```
45git checkout -b dev_branch
46git push --set-upstream origin dev_branch
47```
48
49This creates a new branch named `dev_branch`, checks it out, and then saves the new branch to your fork. The `--set-upstream` argument tells git to use your fork and the `dev_branch` branch every time you use `git push` or `git pull` from this branch. It only needs to be used on the first push; after that, you can safely use `git push` or `git pull`, without the rest of the arguments.
50
51?> With `git push`, you can use `-u` in place of `--set-upstream` &mdash; `-u` is an alias for `--set-upstream`.
52
53You can name your branch nearly anything you want, though it is recommended to name it something related to the changes you are going to make.
54
55By default `git checkout -b` will base your new branch on the branch that is currently checked out. You can base your new branch on an existing branch that is not checked out by adding the name of the existing branch to the command:
56
57```
58git checkout -b dev_branch master
59```
60
61Now that you have a development branch, open your text editor and make whatever changes you need to make. It is recommended to make many small commits to your branch; that way, any change that causes issues can be more easily traced and undone if needed. To make your changes, edit and save any files that need to be updated, add them to Git's *staging area*, and then commit them to your branch:
62
63```
64git add path/to/updated_file
65git commit -m "My commit message."
66```
67
68`git add` adds files that have been changed to Git's *staging area*, which is Git's "loading zone." This contains the changes that are going to be *committed* by `git commit`, which saves the changes to the repo. Use descriptive commit messages so you can know what was changed at a glance.
69
70?> If you've changed multiple files, you can use `git add -- path/to/file1 path/to/file2 ...` to add all your desired files.
71
72## Publishing Your Changes
73
74The last step is to push your changes to your fork. To do this, enter `git push`. Git will then publish the current state of `dev_branch` to your fork.