aboutsummaryrefslogtreecommitdiff
path: root/docs/ja/newbs_best_practices.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/ja/newbs_best_practices.md')
-rw-r--r--docs/ja/newbs_best_practices.md168
1 files changed, 168 insertions, 0 deletions
diff --git a/docs/ja/newbs_best_practices.md b/docs/ja/newbs_best_practices.md
new file mode 100644
index 000000000..ebb7d0fab
--- /dev/null
+++ b/docs/ja/newbs_best_practices.md
@@ -0,0 +1,168 @@
1# Best Practices
2
3<!---
4 original document: ed0575fc8:docs/newbs_best_practices.md
5 $ git diff ed0575fc8 HEAD docs/newbs_best_practices.md
6-->
7
8## Or, "How I Learned to Stop Worrying and Love Git."
9
10This 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.
11
12This document assumes a few things:
13
141. You have a GitHub account, and have [forked the qmk_firmware repository](getting_started_github.md) to your account.
152. You've [set up your build environment](newbs_getting_started.md?id=environment-setup).
16
17
18## Your fork's master: Update Often, Commit Never
19
20It 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.
21
22To 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.
23
24### Updating your master branch
25
26To 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:
27
28```
29git remote add upstream https://github.com/qmk/qmk_firmware.git
30```
31
32To verify that the repository has been added, run `git remote -v`, which should return the following:
33
34```
35$ git remote -v
36origin https://github.com/<your_username>/qmk_firmware.git (fetch)
37origin https://github.com/<your_username>/qmk_firmware.git (push)
38upstream https://github.com/qmk/qmk_firmware.git (fetch)
39upstream https://github.com/qmk/qmk_firmware.git (push)
40```
41
42Now 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.
43
44To update your fork's master, run the following, hitting the Enter key after each line:
45
46```
47git checkout master
48git fetch upstream
49git pull upstream master
50git push origin master
51```
52
53This 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.
54
55### Making Changes
56
57To make changes, create a new branch by entering:
58
59```
60git checkout -b dev_branch
61git push --set-upstream origin dev_branch
62```
63
64This 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.
65
66!> With `git push`, you can use `-u` in place of `--set-upstream` &mdash; `-u` is an alias for `--set-upstream`.
67
68You 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.
69
70By 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:
71
72```
73git checkout -b dev_branch master
74```
75
76Now 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:
77
78```
79git add path/to/updated_file
80git commit -m "My commit message."
81```
82
83`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.
84
85!> 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.
86
87### Publishing Your Changes
88
89The 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.
90
91
92## Resolving Merge Conflicts
93
94Sometimes 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.
95
96### Rebasing Your Changes
97
98A *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.
99
100To start, run the following:
101
102```
103git fetch upstream
104git rev-list --left-right --count HEAD...upstream/master
105```
106
107The `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:
108
109```
110$ git rev-list --left-right --count HEAD...upstream/master
1117 35
112```
113
114The 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.
115
116Now that the current states of both the current branch and the upstream repo are known, we can start a rebase operation:
117
118```
119git rebase upstream/master
120```
121
122This tells Git to undo the commits on the current branch, and then reapply them against QMK's master branch.
123
124```
125$ git rebase upstream/master
126First, rewinding head to replay your work on top of it...
127Applying: Commit #1
128Using index info to reconstruct a base tree...
129M conflicting_file_1.txt
130Falling back to patching base and 3-way merge...
131Auto-merging conflicting_file_1.txt
132CONFLICT (content): Merge conflict in conflicting_file_1.txt
133error: Failed to merge in the changes.
134hint: Use 'git am --show-current-patch' to see the failed patch
135Patch failed at 0001 Commit #1
136
137Resolve all conflicts manually, mark them as resolved with
138"git add/rm <conflicted_files>", then run "git rebase --continue".
139You can instead skip this commit: run "git rebase --skip".
140To abort and get back to the state before "git rebase", run "git rebase --abort".
141```
142
143This 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:
144
145```
146<<<<<<< HEAD
147<p>For help with any issues, email us at support@webhost.us.</p>
148=======
149<p>Need help? Email support@webhost.us.</p>
150>>>>>>> Commit #1
151```
152
153The 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.
154
155Because 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.
156
157```
158<p>Need help? Email support@webhost.us.</p>
159```
160
161Now run:
162
163```
164git add conflicting_file_1.txt
165git rebase --continue
166```
167
168Git logs the changes to the conflicting file, and continues applying the commits from our branch until it reaches the end.