forked from open-sauced/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: simplified the merge conflicts section (open-sauced#232)
* fix: Clarify resolving merge conflicts section * Update docs/contributing/technical/resolve-merge-conflicts.md Co-authored-by: Ayu Adiati <[email protected]> * fix: clearing up upstream directions * docs: add punctuations and fix capitalization for consistency --------- Co-authored-by: Ayu Adiati <[email protected]> Co-authored-by: Ayu Adiati <[email protected]>
- Loading branch information
1 parent
5cb1744
commit 6ce00fa
Showing
3 changed files
with
44 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,138 +6,92 @@ keywords: | |
- "resolve merge conflicts" | ||
--- | ||
|
||
You'll likely encounter merge conflicts when opening a pull request, as the release process generally updates `npm-shrinkwrap.json`. | ||
When you are working on any of the OpenSauced repositories, you might run into a merge conflict. A merge conflict occurs when multiple conflicting changes are made to the same line in a file. Merge conflicts happen the most when you open a pull request, as the release process generally updates `npm-shrinkwrap.json`. | ||
|
||
To better illustrate the commands listed here, we will use commits and screenshots from [open-sauced#1078](https://github.com/open-sauced/open-sauced/pull/1078). | ||
In this guide, we will talk about how to resolve merge conflicts and how to keep your branch up to date. | ||
|
||
## Repository Setup | ||
## How to Keep Your Branch Updated | ||
|
||
Fork and clone the project using the `gh` command line interface: | ||
It is common for your branch to fall behind the main repository's branch. So it is important to keep it up to date as you are contributing. | ||
|
||
```shell | ||
gh repo clone 0-vortex/open-sauced | ||
``` | ||
### Using GitHub | ||
|
||
Running `git remote -v` will output: | ||
To update your branch on GitHub, you can go to your forked copy of the project and click on `Sync fork` and then the `Update branch` button. | ||
|
||
```shell | ||
origin [email protected]:0-vortex/open-sauced.git (fetch) | ||
origin [email protected]:0-vortex/open-sauced.git (push) | ||
upstream [email protected]:open-sauced/open-sauced.git (fetch) | ||
upstream [email protected]:open-sauced/open-sauced.git (push) | ||
``` | ||
![syncing your branch on GitHub](../../../static/img/sync-branch-GH.png) | ||
|
||
Fork and clone the project using the `git` command line interface: | ||
### Using Git | ||
|
||
```shell | ||
git clone [email protected]:0-vortex/open-sauced.git | ||
``` | ||
To update your branch using Git and the terminal, you can use the following commands: | ||
|
||
Running `git remote -v` will output: | ||
1. Change directories to the correct project. | ||
|
||
```shell | ||
origin [email protected]:0-vortex/open-sauced.git (fetch) | ||
origin [email protected]:0-vortex/open-sauced.git (push) | ||
```bash | ||
cd project-name | ||
``` | ||
|
||
As an additional step for this tutorial, we need to add the `upstream` remote: | ||
2. Add the `upstream` remote. | ||
|
||
```shell | ||
git remote add upstream git@github.com:open-sauced/open-sauced.git | ||
```bash | ||
git remote add upstream https://github.com/upstream-username/upstream-repository.git | ||
``` | ||
3. Pull the latest changes from the `upstream`. | ||
|
||
## Update | ||
|
||
First, get the default branch changes: | ||
|
||
```shell | ||
git fetch origin --recurse-submodules=no --progress --prune | ||
git checkout main -- | ||
git fetch upstream --recurse-submodules=no --progress --prune | ||
git merge upstream/main --no-stat -v | ||
``` | ||
|
||
## Merge with `upstream` | ||
|
||
Then merge with the forked up-to-date `beta` (default branch): | ||
|
||
```shell | ||
git merge origin/main --no-ff -v | ||
```bash | ||
git pull upstream main-branch-name | ||
``` | ||
|
||
You will see something similar to: | ||
**Note**: Some of the OpenSauced repositories will use `main` for the main branch while others like the [app repository](https://github.com/open-sauced/app), will use `beta` for the main branch name. | ||
|
||
![proper merge but results in conflicts](../../../static/img/contributing-resolve-merge-conflicts-merge-conflicts.png) | ||
## How to Check for Merge Conflicts Locally | ||
|
||
## Review Changes | ||
If you are actively working on a change to an OpenSauced repository, you can check for potential merge conflicts by running a few commands in the terminal. | ||
|
||
To see what the changes are, run the command below: | ||
1. Make sure you are on the correct branch where the changes are being made. | ||
|
||
```shell | ||
git diff package.json | ||
```bash | ||
cd app | ||
git checkout <your-branch> | ||
``` | ||
|
||
It will look like this: | ||
2. Fetch the latest changes from the OpenSauced main repository. | ||
|
||
![review merge conflicts](../../../static/img/contributing-resolve-merge-conflicts-review-conflicts.png) | ||
|
||
## Resolve Conflicts | ||
|
||
Since this pull request does not modify the `package.json` file, it is safe to fast-forward the changes from `origin/main`: | ||
|
||
```shell | ||
# overwrite with origin/main changes | ||
git show :3:package.json > package.json | ||
```bash | ||
git fetch upstream | ||
``` | ||
|
||
A more traditional way of doing the same thing is: | ||
3. See the differences between your branch and the OpenSauced main branch. | ||
|
||
```shell | ||
# make a local copy of all changes and use --theirs | ||
# --theirs strategy overwrite with origin/main changes | ||
git show :1:package.json > base.package.json | ||
git show :2:package.json > branch.package.json | ||
git show :3:package.json > head.package.json | ||
git merge-file -p --theirs \ | ||
branch.package.json base.package.json head.package.json > package.json | ||
```bash | ||
git diff <your-branch> upstream/main | ||
``` | ||
|
||
## Commit Changes | ||
**Note**: Some of the OpenSauced repositories will use `main` for the main branch while others, like the [app repository](https://github.com/open-sauced/app), will use `beta` for the main branch name. | ||
|
||
Not making any assumptions about editor preferences, running this will open the configured editor with a default commit message: | ||
![git diff output review conflicts](../../../static/img/contributing-resolve-merge-conflicts-review-conflicts.png) | ||
|
||
```shell | ||
git commit | ||
``` | ||
**NOTE**: If you have already opened up a pull request, then you can see if there is a conflict at the bottom of the PR. Even though it is possible to resolve conflicts through GitHub, it is best practice to resolve them locally. | ||
|
||
That should look like this: | ||
![merge conflicts git message](../../../static/img/contributing-resolve-merge-conflicts-dont-do.png) | ||
|
||
![commit merge message](../../../static/img/contributing-resolve-merge-conflicts-commit-message.png) | ||
## How to Resolve Merge Conflicts | ||
|
||
## Push Changes | ||
If you have merge conflicts, it is best to use a text editor to resolve them. Identify the conflicting files and open them up in your editor of choice. For the conflicting sections, you have an option to either keep the incoming changes, keep your changes or keep both sets of changes. The conflicting sections will be marked with `<<<<<<<`, `=======`, and `>>>>>>>` symbols. | ||
|
||
One more security check to make sure your branch has not diverged and push: | ||
Here is a [guide](https://dev.to/opensauced/keeping-your-branch-up-to-date-and-handling-merge-conflicts-while-waiting-for-pr-reviews-3b3h) for an in depth walkthrough of the process. Once you have resolved all of the conflicts, then you can stage, commit and push your changes to your branch. | ||
|
||
```shell | ||
```bash | ||
git status | ||
git add . | ||
git commit -m "fix: resolving merge conflicts" | ||
git push | ||
``` | ||
|
||
It should look something like this: | ||
|
||
![push updated pr](../../../static/img/contributing-resolve-merge-conflicts-merge-success.png) | ||
|
||
## Review Your Pull Request | ||
|
||
The result of the above commands can be viewed at [283ff8cd788c550309ff0d1d5a9a5a97ec0731b2](https://github.com/open-sauced/open-sauced/pull/1078/commits/283ff8cd788c550309ff0d1d5a9a5a97ec0731b2). | ||
|
||
GitHub will conveniently display only your merge conflict changes: | ||
|
||
![view merge commit](../../../static/img/contributing-resolve-merge-conflicts-view-merge-commit.png) | ||
## Reviewing Your Pull Request | ||
|
||
And it's ready to merge: | ||
Once you have pushed up your changes, you can review them in your pull request. Under the files changed tab, you will see all of the recent changes including all conflicts resolved. | ||
|
||
![ready to merge](../../../static/img/contributing-resolve-merge-conflicts-ready-to-merge.png) | ||
![files changed tab on GitHub](../../../static/img/files-changed-tab.png) | ||
|
||
## Dependency Updates | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.