-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-actions.txt
More file actions
377 lines (255 loc) · 12.6 KB
/
github-actions.txt
File metadata and controls
377 lines (255 loc) · 12.6 KB
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
This document contains git commands that need to be used in order to synchronize branches of the main repository.
These are just for info with an explanation of what they do:
git checkout main
git pull origin main
git checkout -b feature-branch-name
git push origin feature-branch-name
1. git checkout main
This command switches your current branch to the main branch. If you are on a different branch, this will move you to the main branch.
2. git pull origin main
This command fetches the latest changes from the main branch on the remote repository (referred to as origin) and merges them into your local main branch. This ensures your local main branch is up-to-date with the remote repository.
3. git checkout -b feature-branch-name
This command creates a new branch called feature-branch-name and switches to it immediately. The new branch is created based on the branch you were on before running this command, typically the main branch.
4. git push origin feature-branch-name
This command pushes your newly created branch (feature-branch-name) to the remote repository (referred to as origin). This makes your branch available to others who have access to the repository.
By using these commands, you can create a new branch for your feature, ensure it is based on the latest state of the main branch, and then push it to the remote repository for collaboration.
*****************************************************************
*****************************************************************
We often see the message "This branch is 'n' commits behind 'master'.
This is how to resolve it so the message reads "This branch is up to date with 'master'.
Resolving n commits behind master:
git checkout master - to switch to the master branch
git pull origin master - to pull the latest changes from master
git checkout stu - to switch back to the stu branch
git merge master - to merge the latest changes from master into stu
git push origin stu - to push the updated stu branch to the remote repository
for Stu:
**********
git checkout master
git pull origin master
git checkout stu
git merge master
git push origin stu
For Nette:
**********
git checkout master
git pull origin master
git checkout nette
git merge master
git push origin nette
*****************************************************************
*****************************************************************
Reference - some git commands & what they do
*****************************************************************
*****************************************************************
git status - list all new or modified files to be committed
git add . - adds all the files in the local repo and stages them for commits
git reset HEAD <file> - to unstage a specific file
git add FILENAME.ext - add a specific file e.g. git add README.txt
git commit -m "your commit message" - commit files you added to the local repo
git reset HEAD~1 - remove the most recent commit
git remote -v - list remote repos you are connected to
git push -u origin branchname - push changes to the remote repo 'branchname'
git diff - show file changes not yet staged (press 'q' to quit the command)
git checkout . - revert back to the last committed version of the repo
or:
git checkout -- <filename> - revert back to the last committed version of a specific file
git log - view the commit history of your files (q to quite the cmd)
Each time you make changes that you want to be reflected on GitHub, the following are the most common flow of commands:
$ git add .
$ git status # Lists all new or modified files to be committed
$ git commit -m "Second commit"
$ git push -u origin master
*****************************************************************
*****************************************************************
Testing collaborator's changes before merging:
1. Fetch all branches from the remote repository:
git fetch origin
2. Check out the collaborator's branch:
git checkout nette
# If the branch does not exist locally, use:
# git checkout -b nette origin/nette
2.5 Pull the latest changes into the local `nette` branch
git pull origin nette
# You should now see the changes that have been made & commited to the `nette` branch by nette
# If you can not see the changes, check the current branch, check for uncommited changes, then compare the local branch with the remote branch:
git branch
git status
git diff origin/nette
3. Test the changes:
Run any tests or perform any manual testing required to verify the changes made by the collaborator.
4. Merge the collaborator's branch into a local master branch:
git checkout master
git pull origin master
git merge nette
5. Push the changes to the remote master branch:
git push origin master
Pushing a local branch to GitHub:
1. Ensure you are on the `nette` branch:
git checkout nette
2. Push the `nette` branch to the remote repository:
git push origin nette
*****************************************************************
*****************************************************************
*****************************************************************
Ensuring 'nette' has the latest changes from 'stu':
*****************************************************************
We need to make sure that everything is up to date with github BEFORE we
start to make changes to ANY file in VS Code.
#Open VS Code (the code editor)
#Open a terminal:
Press CTRL and hold while you press ' (it's on the same key as the @ symbol)
#When the terminal is open, you need to open Git Bash:
Press the down arrow (next to the '+' symbol) on top right hand side of the terminal window.
Select 'Git Bash' from the pop up menu.
#Now we can run the following commands to ensure that your branch (nette) is up to date with my branch (stu):
*****************************************************************
Ensuring 'nette' has the latest changes from 'stu' continued:
*****************************************************************
Ensuring 'nette' has the latest changes from 'stu':
1. Fetch the latest changes from the remote repository:
git fetch origin
2. Check if the `stu` branch exists locally. It should be shown in the terminal in green text:
git branch --list stu
3. If the `stu` branch exists locally, check it out ('checkout' means 'switch to'):
git checkout stu
4. If the `stu` branch does not exist locally, create a local copy of the remote `stu` branch:
git checkout -b stu origin/stu
# Now we are sure the 'stu' branch exists on your pc we can proceed:
5. Pull the latest changes into the `stu` branch:
git pull origin stu
6. Check out (switch to) the `nette` branch:
git checkout nette
7. Merge the `stu` branch into the `nette` branch:
git merge stu
8. Resolve any merge conflicts if they arise.
# If there are conflicts, STOP and go no further. Otherwise proceed:
9. Push the updated `nette` branch to the remote repository:
git push origin nette
###### Below is a shorter version of the above!!!!! ######
#Copy and paste these into a Git bash terminal and press 'Enter':
# Run these commands first (copy & paste into the 'Git Bash' terminal & press 'Enter'):
git fetch origin
git branch --list stu
# If the `stu` branch exists locally:
#(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git checkout stu
git pull origin stu
# If the `stu` branch does not exist locally:
#(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git checkout -b stu origin/stu
# Now we know the 'stu' branch definately exist on your pc:
#(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git pull origin stu
git checkout nette
git merge stu
WARNING: If there are conflicts, STOP!!! Do no more, these have to be fixed!!!
#Then, if there are no conflicts
##(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git push origin nette
*****************************************************************
Ensure stu has the latest updates from nette:
# Run these commands first (copy & paste into the 'Git Bash' terminal & press 'Enter'):
git fetch origin
git branch --list nette
# If the `nette` branch exists locally:
#(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git checkout nette
git pull origin nette
# If the `nette` branch does not exist locally:
#(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git checkout -b stu origin/nette
# Now we know the 'stu' branch definately exist on your pc:
#(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git pull origin nette
git checkout stu
git merge nette
WARNING: If there are conflicts, STOP!!! Do no more, these have to be fixed!!!
#Then, if there are no conflicts
##(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git push origin stu
*****************************************************************
*****************************************************************
Ensuring 'stu' has the latest changes from 'nette'
*****************************************************************
git fetch origin
git branch --list nette
# If the `nette` branch exists locally:
#(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git checkout nette
git pull origin nette
# If the `nette` branch does not exist locally:
#(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git checkout -b nette origin/nette
# Now we know the 'stu' branch definately exist on your pc:
#(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git pull origin nette
git checkout stu
git merge nette
WARNING: If there are conflicts, STOP!!! Do no more, these have to be fixed!!!
#Then, if there are no conflicts
##(copy & paste the following into the 'Git Bash' terminal & press 'Enter'):
git push origin stu
*****************************************************************
Deleting a local branch:
1. Ensure you are not on the `nuttysedits` branch:
git branch
# If you are on the `nuttysedits` branch, switch to another branch:
git checkout master
2. Delete the `nuttysedits` branch:
git branch -d nuttysedits
# If the branch has not been merged and you want to force delete it, use:
git branch -D nuttysedits
*****************************************************************
*****************************************************************
Resolving Conflicts
*****************************************************************
*****************************************************************
When facing many conflicts, you have several options:
Option 1 - Start Fresh:
# Delete your local changes and get a fresh copy
git checkout master
git pull origin master
git checkout -b new-stu-branch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Option 2 - Create a Backup and Reset:
# Backup your changes
git checkout stu
git branch stu-backup
# Reset your branch to match master
git reset --hard origin/master
# Then make your changes again
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Option 3 - Resolve Conflicts File by File:
# Stay on your branch and merge master
git checkout stu
git merge master
# Then resolve conflicts one file at a time using:
git checkout --ours filename.html # Keep your version
# OR
git checkout --theirs filename.html # Keep master's version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Option 4 - Cherry-pick Changes:
# Create a new branch from master
git checkout master
git checkout -b new-stu-branch
# Then cherry-pick specific commits from your old branch
git cherry-pick <commit-hash>
*****************************************************************
*****************************************************************
Undo A Commit Safely
*****************************************************************
*****************************************************************
A safe way to undo a commit is to create a new commit that undoes
the changes:
git revert HEAD # Creates a new commit that undoes the last commit
git push origin stu
*****************************************************************
*****************************************************************
To clean up the local references to remote branches that no longer exist on the remote repository, you can use the git remote prune command. This will remove the local references to remote branches that have been deleted on the remote repository.
Cleaning up remote branches:
1. Prune the remote branches:
git remote prune origin
2. Verify the remote branches:
git branch -r
# Ensure only the actual remote branches are listed: master, stu, nette