Skip to content

Commit b41737c

Browse files
committed
05: Add exercises
1 parent 822e8cc commit b41737c

5 files changed

+98
-10
lines changed

episodes/05-resolving-conflicts.md

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,114 @@ To keep the conflict on the code — not between people — we’ll practice bre
2828

2929
### Exercise 05.1
3030

31-
Exercise with your pair to add content to you shared repository in two different branches. Learn how to update your working branch with contents of the updated remote.
31+
Exercise with your pair to add content to you shared repository in the default branch. You can do so if both of you have at least maintainer rights to the repository. Learn how to update your working area with contents of the updated remote.
32+
33+
One of you makes a new local edits. Meanwhile, the other one updates the remote default branch with new files.
3234

33-
Use `git rebase`.
3435

3536
:::::::::::::::: solution
3637

37-
See https://git-scm.com/docs/git-rebase
38+
If you try to push, you will see a message like this:
39+
40+
```
41+
! [rejected] main -> main (fetch first)
42+
error: failed to push some refs to 'gitlab.com:katilp/tutorial-test.git'
43+
hint: Updates were rejected because the remote contains work that you do not
44+
hint: have locally. This is usually caused by another repository pushing to
45+
hint: the same ref. If you want to integrate the remote changes, use
46+
hint: 'git pull' before pushing again.
47+
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
48+
```
49+
50+
A bare `git pull`, as suggested in the message most likely gives:
51+
52+
```
53+
2f8c69a..d32176b main -> origin/main
54+
hint: You have divergent branches and need to specify how to reconcile them.
55+
hint: You can do so by running one of the following commands sometime before
56+
hint: your next pull:
57+
hint:
58+
hint: git config pull.rebase false # merge
59+
hint: git config pull.rebase true # rebase
60+
hint: git config pull.ff only # fast-forward only
61+
hint:
62+
hint: You can replace "git config" with "git config --global" to set a default
63+
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
64+
hint: or --ff-only on the command line to override the configured default per
65+
hint: invocation.
66+
```
67+
68+
Get the remote changes with
69+
70+
```
71+
git pull --rebase
72+
```
73+
74+
and then push your updates.
75+
76+
Did this work in your case?
3877

3978
:::::::::::::::::::::::::
4079
:::::::::::::::::::::::::::::::::::::::::::::::
4180

81+
::::::::::::::::::::::::::::::::::::: challenge
4282

43-
::::::::::::::::::::::::::::::::::::: callout
44-
### Remember to update your local main/master branch!!!
83+
### Exercise 05.2
84+
85+
Exercise with your pair to add content to you shared repository in two different branches. Learn how to update your working branch with contents of the updated remote.
86+
87+
One of you makes a new local edits to a local working branch. Meanwhile, the other one updates the remote default branch with new files.
88+
89+
90+
:::::::::::::::: solution
91+
92+
Create a new branch, make edits, and push them to the shared repository with
93+
94+
```
95+
git push origin <your branch name>
96+
```
4597

46-
Always remember to update your local default branch.
98+
Then make a merge request from the GitLab Web UI.
99+
100+
If the branches diverge you will see a message about it and you can click on "Rebase source branch" and accept
101+
102+
![](fig/gitlab-diverged-branch-rebase.png)
103+
104+
GitLab checks for conflicts
105+
106+
![](fig/gitlab-diverged-branch-check-conflicts.png)
107+
108+
and once done gives
109+
110+
![](fig/gitlab-diverged-branch-block.png)
111+
112+
Follow the link, and if there are no conflicts, your can merge again.
113+
114+
Note that you could have avoided this by rebasing before pushing. You could have refreshed your main:
47115

48116
```
49117
git checkout main
50118
git pull
51119
```
52120

53-
Do this every time when you start a new development.
121+
then moved to your working branch and rebased
54122

55-
::::::::::::::::::::::::::::::::::::::::::::::::
123+
```
124+
git checkout <your branch name>
125+
git rebase
126+
```
127+
128+
:::::::::::::::::::::::::
129+
:::::::::::::::::::::::::::::::::::::::::::::::
56130

57131

58132

59133
::::::::::::::::::::::::::::::::::::: challenge
60134

61-
### Exercise 05.2
135+
### Exercise 05.3
62136

63137
With your pair, make local edits to the same file in the shared repository.
64-
Observe the error messages when trying to push and learn to solve conflicts with confidence!
138+
Observe the error messages when trying to merge and learn to solve conflicts with confidence!
65139

66140
Exercise conflict solving on the GitLab Web UI and with the Git command line tools.
67141

@@ -76,6 +150,20 @@ See https://docs.gitlab.com/user/project/merge_requests/conflicts/
76150

77151

78152

153+
::::::::::::::::::::::::::::::::::::: callout
154+
### Remember to update your local main/master branch!!!
155+
156+
You will avoid a good amount of problems, if you remember to update your local default branch.
157+
158+
```
159+
git checkout main
160+
git pull
161+
```
162+
163+
Do this every time when you start a new development.
164+
165+
::::::::::::::::::::::::::::::::::::::::::::::::
166+
79167
::::::::::::::::::::::::::::::::::::: keypoints
80168

81169
- Git is the tool to handle collaborative work.
24 KB
Loading
36.9 KB
Loading
82.5 KB
Loading
96.8 KB
Loading

0 commit comments

Comments
 (0)