Skip to content

Commit 15d9beb

Browse files
how to update the incoming changes from updatream
1 parent a23cc57 commit 15d9beb

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# empty-object-with-newline check and formatter
2+
3+
In Shopify theme development, there is a GitHub bot which pulls in changes in GitHub repos.
4+
Sadly it formats .json files in a non standard way. Hence, every empty object get's a newline, which doesn't not conform to standard formatting.
5+
This creates then a new commit in the branch, which is pushed back into the origin repo. Which needs to be pulled to be able to push again. It's creating a cycle.
6+
7+
Hence, I created the formatting option --empty-object-with-newline to conform to the Shopify .json formatting to prevent commit pollution.
8+
9+
Sadly, this was not added as my pull request got declined. Hence, I kept the for up.
10+
11+
## Synch upstream changes
12+
13+
This Claude 3 Opus conversation gives the solution on how to merge in the upstream changes.
14+
15+
### Prompt 1
16+
17+
I have forked a github repo and added some commits to the main branch. Sadly, they didn't get merged with my pull request.
18+
19+
I would like to move the last 4 commits now in a branch, to be able to update from the upstream repo
20+
21+
### Response 1
22+
23+
Here are the steps to move your last 4 commits from the main branch to a new branch:
24+
25+
1. Make sure you're on the main branch:
26+
27+
```bash
28+
git checkout main
29+
```
30+
31+
2. Create a new branch and switch to it, e.g., named "feature-branch":
32+
33+
```bash
34+
git checkout -b feature-branch
35+
```
36+
37+
3. Move the main branch back by 4 commits, keeping the changes in your current branch:
38+
39+
```bash
40+
git branch -f main HEAD~4
41+
```
42+
43+
This effectively moves the main branch back by 4 commits, while your current branch (feature-branch) retains the commits.
44+
45+
4. Push the updated main branch to your forked repository (assuming your remote is named "origin"):
46+
47+
```bash
48+
git push origin main --force
49+
```
50+
51+
Note: Using --force is necessary because you're rewriting the history of the main branch. Make sure you're aware of the implications and that it's safe to do so.
52+
53+
5. Your feature-branch now contains the last 4 commits. You can push this branch to your forked repository:
54+
55+
```bash
56+
git push origin feature-branch
57+
```
58+
59+
After these steps, your main branch will be synchronized with the upstream repository, and your last 4 commits will be in the feature-branch.
60+
61+
To update your forked repository with the latest changes from the upstream repository, you can do the following:
62+
63+
1. Add the upstream repository as a remote (if you haven't already):
64+
65+
```bash
66+
git remote add upstream <UPSTREAM_REPO_URL>
67+
```
68+
69+
2. Fetch the latest changes from the upstream repository:
70+
71+
```bash
72+
git fetch upstream
73+
```
74+
75+
3. Merge the upstream changes into your main branch:
76+
77+
```bash
78+
git checkout main
79+
git merge upstream/main
80+
```
81+
82+
4. Push the updated main branch to your forked repository:
83+
84+
```bash
85+
git push origin main
86+
```
87+
88+
Now your forked repository's main branch will be up to date with the upstream repository, and you can work on your feature-branch separately.
89+
90+
### Prompt 2
91+
92+
I followed the instructions,but did the update of the repo from the upstream repo with the github online functionality, which worked fine.
93+
94+
Now I created a pull request on github, which has merge conflicts.
95+
96+
How can I resolve them locally?
97+
98+
### Response 2
99+
100+
To resolve merge conflicts locally for a pull request, you can follow these steps:
101+
102+
1. Ensure that your local main branch is up to date with the upstream repository:
103+
104+
```bash
105+
git checkout main
106+
git fetch upstream
107+
git merge upstream/main
108+
```
109+
110+
2. Fetch the changes from your forked repository (assuming your remote is named "origin"):
111+
112+
```
113+
git fetch origin
114+
```
115+
116+
3. Check out the branch that has the merge conflicts (in this case, "feature-branch"):
117+
118+
```
119+
git checkout feature-branch
120+
```
121+
122+
4. Merge the main branch into your feature-branch:
123+
124+
```
125+
git merge main
126+
```
127+
128+
Git will highlight the files with merge conflicts.
129+
130+
5. Open the conflicting files in a text editor and look for the conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`). Resolve the conflicts by manually editing the files, deciding which changes to keep from your branch and which changes to keep from the main branch.
131+
132+
6. After resolving the conflicts, remove the conflict markers and save the files.
133+
134+
7. Stage the resolved files:
135+
136+
```
137+
git add <resolved-file1> <resolved-file2> ...
138+
```
139+
140+
8. Commit the changes:
141+
142+
```
143+
git commit -m "Resolve merge conflicts"
144+
```
145+
146+
9. Push the updated feature-branch to your forked repository:
147+
148+
```
149+
git push origin feature-branch
150+
```
151+
152+
After pushing the changes, the pull request on GitHub should automatically update, and the merge conflicts should be resolved.
153+
154+
If you encounter any issues or have further questions, feel free to ask!

0 commit comments

Comments
 (0)