1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
GIT [0]
________________________________________________________________________________
Git is a free and open source distributed version control system designed to
handle everything from small to very large projects with speed and efficiency.
[0.0] Index
________________________________________________________________________________
- Git Commands [1.0]
- Example 1: Staying Up-to-Date [2.0]
- Example 2: Squashing Your Latest Commits Into One [3.0]
- Example 3: Writing a new KISS Wiki article [4.0]
- References [5.0]
[1.0] Git Commands
________________________________________________________________________________
New KISS users may have various levels of exposure to git and other forms of
version control systems. The following is intended to be a "quick" reference
sheet of git commands.
+-------------------+----------------------------------------------------------+
| Action | Command |
+-------------------+----------------------------------------------------------+
| | |
| Set Default | $ git config --global user.name "FIRSTNAME LASTNAME" |
| Username | # stored in ~/.gitconfig |
| | |
| Set Default | $ git config --global user.email "EMAIL@EXAMPLE.COM" |
| Email Address | # stored in ~/.gitconfig |
| | |
| Set Default | $ git config --global core.editor vim |
| Text Editor | # stored in ~/.gitconfig |
| | |
| Store User | $ git config credential.helper store |
| Credentials | # credentials saved in ~/.git-credentials |
| | |
| Clone Repo. | $ git clone GIT_URL |
| | |
| Clone Branch | $ git clone GIT_URL -b BRANCH_NAME |
| | |
| Repo. Status | $ git status |
| | |
| Add/Update | $ git add FILE_OR_PATH |
| Project Files | |
| | |
| Apply a patch | $ git apply PATH_FILE |
| | |
| Remove | $ git add FILE_OR_PATH |
| Project Files | |
| | |
| Checkout | $ git checkout BRANCH_NAME |
| | # switch branches or restore working tree files |
| | |
| Commit | $ git commit |
| | # records changes to the repository |
| | |
| Push | $ git push |
| | # updates remote refs along with associated objects |
| | |
| Pull | $ git pull |
| | # fetch and integrate with another repository/branch |
| | |
| Fetch | $ git fetch |
| | # download objects and refs from another repository |
| | |
| Merge | $ git merge |
| | # join two or more development histories together |
| | |
| Rebase | $ git rebase |
| | # reapply commits on top of another base tip |
| | |
+-------------------+----------------------------------------------------------+
[2.0] Example 1: Staying Up-to-Date [1]
________________________________________________________________________________
In a standard setup, you generally have an origin and an upstream remote - the
latter being the gatekeeper of the project or the source of truth to which you
wish to contribute.
First, verify that you have already setup a remote for the upstream repository,
and hopefully an origin too:
+------------------------------------------------------------------------------+
| |
| $ git remote -v |
| |
+------------------------------------------------------------------------------+
If you don't have an upstream you can easily add it with the remote command:
+------------------------------------------------------------------------------+
| |
| $ git remote add upstream UPSTREAM_URL |
| |
+------------------------------------------------------------------------------+
Now you can collect the latest changes of the upstream repository with fetch.
Repeat this every time you want to get updates:
+------------------------------------------------------------------------------+
| |
| $ git fetch upstream |
| |
+------------------------------------------------------------------------------+
Generally, you want to keep your local master branch as a close mirror of the
upstream master and execute any work in feature branches, as they might later
become pull requests.
At this point, it does not matter if you use merge or rebase, as the result
will typically be the same. Let's use merge:
+------------------------------------------------------------------------------+
| |
| $ git checkout master |
| $ git merge upstream/master |
| |
+------------------------------------------------------------------------------+
[3.0] Example 2: Squashing Your Latest Commits Into One [2]
________________________________________________________________________________
With git it’s possible to squash previous commits into one. This is a great way
to group certain changes together before sharing them with others. Let’s say
this is your current git log:
+------------------------------------------------------------------------------+
| |
| * df71a27 - (HEAD feature_x) Updated CSS for new elements (4 minutes ago) |
| * ba9dd9a - Added new elements to page design (15 minutes ago) |
| * f392171 - Added new feature X (1 day ago) |
| * d7322aa - (origin/feature_x) Proof of concept for feature X (3 days ago) |
| |
+------------------------------------------------------------------------------+
You have a branch “feature_x” here. You’ve already pushed d7322aa with the proof
of concept of the new feature X. After that you’ve been working to add new
element to the feature, including some changes in CSS. Now, you want to squash
your last three commits in one to make your history look pretty.
The command to accomplish that is:
+------------------------------------------------------------------------------+
| |
| $ git rebase -i HEAD~3 |
| |
+------------------------------------------------------------------------------+
This will open up your editor with the following:
+------------------------------------------------------------------------------+
| |
| pick f392171 Added new feature X |
| pick ba9dd9a Added new elements to page design |
| pick df71a27 Updated CSS for new elements |
| |
+------------------------------------------------------------------------------+
Now you can tell git what to do with each commit. Let’s keep the commit f392171,
the one were we added our feature. We’ll squash the following two commits into
the first one - leaving us with one clean commit with features X in it,
including the added element and CSS.
Change your file to this:
+------------------------------------------------------------------------------+
| |
| pick f392171 Added new feature X |
| squash ba9dd9a Added new elements to page design |
| squash df71a27 Updated CSS for new elements |
| |
+------------------------------------------------------------------------------+
When done, save and quit your editor. Git will now squash the commits into one.
Note: Do not squash commits that you’ve already shared with others. You are
changing history and it will cause trouble for others.
[4.0] Example 3: Writing a new KISS Wiki article.
________________________________________________________________________________
Note: Specifics of this example are not relevant to this wiki; information about
contributing to this wiki can be found at
https://kisscommunity.bvnf.space/website/.
Note: The method described below requires a GitHub user account. If you do not
have a GitHub user account or do not wish to create one, you can still
submit your articles or ideas directly to dylan@k1ss.org.
Lets say you are interested in writing a new article for the KISS Wiki. The
process is fairly straight forward!
Begin by first creating a fork of the KISS Wiki repository. One way to do this
is from a web browser by going to the https://github.com/kiss-community/wiki
page, clicking the "Fork" button in the upper right corner of the page. Doing so
should create a copy of the KISS Wiki repository on your user account (e.g.
https://github.com/USERNAME/wiki).
Clone the forked repository to your PC with the following command. Remember to
replace USERNAME with your actual GitHub username.
+------------------------------------------------------------------------------+
| |
| $ git clone https://github.com/USERNAME/wiki.git |
| |
+------------------------------------------------------------------------------+
Once cloned to your PC, navigate to the wiki directory:
+------------------------------------------------------------------------------+
| |
| $ cd wiki |
| |
+------------------------------------------------------------------------------+
Add your new article in this directory per the #/wiki/help/adding-a-page
guidelines. Once you are ready to publish your newly created article, you need
to add/update your forked repository. From the main wiki directory, you can
check the status of all changes or newly created files:
+------------------------------------------------------------------------------+
| |
| $ git status |
| |
+------------------------------------------------------------------------------+
Using the output of command above, update/add the new files your forked
repository that are ready to be published:
+------------------------------------------------------------------------------+
| |
| $ git add FILE_NAME1 FILE_NAME |
| |
+------------------------------------------------------------------------------+
Alternatively, you can add ALL newly updated/created files in a single command:
+------------------------------------------------------------------------------+
| |
| $ git add * |
| |
+------------------------------------------------------------------------------+
Next, you will commit your changes.
+------------------------------------------------------------------------------+
| |
| $ git commit -m "YOUR_COMMIT_MSG" |
| |
+------------------------------------------------------------------------------+
Replace YOUR_COMMIT_MSG with a short description of change(s) or the new article
(i.e. "git: new article" or "git: add new git example").
At this point you are ready to push your changes to the GitHub server with the
following command.
+------------------------------------------------------------------------------+
| |
| $ git push |
| |
+------------------------------------------------------------------------------+
Upon doing so, you will be prompted to enter your GitHub user credentials. Once
entered, the latest changes will be uploaded to your forked Wiki repository
on GitHub.
The last step is to initiate a Pull Request (PR). A PR can be initiated via a
web browser by going to the https://github.com/USERNAME/wiki page and pressing
the "New pull request" button near the top of the page. In the Title field,
enter the reason for initiating a PR (i.e. "git: new article") and press the
"Create pull request" button.
Note: Pay attention to which branch is being merged into the master branch of
the repository :kiss-community/wiki".
[5.0] References
________________________________________________________________________________
[0] https://git-scm.com
[1] https://www.atlassian.com/git/tutorials/git-forks-and-upstreams
[2] https://www.devroom.io/2011/07/05/git-squash-your-latests-commits-into-one/
|