|
| 1 | +# How to Resolve Merge Conflicts via Terminal (CLI Guide) |
| 2 | + |
| 3 | +This guide goes along with the GitHub web UI guide. Here, we will focus on fixing merge conflicts using Git in your terminal. Here's a step-by-step guide so beginners can follow easily. |
| 4 | + |
| 5 | +### Step 1: Clone the Repository |
| 6 | + |
| 7 | +1. First, fork the repository on GitHub. Then clone your fork locally with this command: |
| 8 | + |
| 9 | +```bash |
| 10 | +git clone https://github.com/<your-username>/zoea-opensource.git |
| 11 | +``` |
| 12 | + |
| 13 | +*Replace `<your-username>` with your GitHub username.* |
| 14 | + |
| 15 | +2. Move into the project directory: |
| 16 | +```bash |
| 17 | +cd zoea-opensource |
| 18 | +``` |
| 19 | + |
| 20 | +### Step 2: Checkout the Conflict Branch |
| 21 | + |
| 22 | +1. Fetch all remote branches with the following command: |
| 23 | + |
| 24 | +```bash |
| 25 | +git fetch origin |
| 26 | +``` |
| 27 | + |
| 28 | +2. Then switch to the branch assigned to you. |
| 29 | +```bash |
| 30 | +git checkout <conflict-branch-name> |
| 31 | +``` |
| 32 | +*Replace `<conflict-branch-name>` with the branch provided in the issue comment* |
| 33 | +### Step 3: Merge Main into Your Branch |
| 34 | + |
| 35 | +Merge changes from the main branch into your conflict branch: |
| 36 | + |
| 37 | +```bash |
| 38 | +git merge main |
| 39 | +``` |
| 40 | + |
| 41 | +*Git will notify you if there are conflicts* |
| 42 | + |
| 43 | +### Step 4: Identify Conflicts |
| 44 | + |
| 45 | +Check which files have conflicts and view what exactly is conflicting with: |
| 46 | + |
| 47 | +```bash |
| 48 | +git status |
| 49 | +``` |
| 50 | + |
| 51 | +To see the exact differences, use: |
| 52 | +```bash |
| 53 | +git diff |
| 54 | +``` |
| 55 | + |
| 56 | +### Step 5: Resolve Conflicts |
| 57 | + |
| 58 | +Open the conflicted file in your text editor. You'll see markers like this: |
| 59 | + |
| 60 | +```bash |
| 61 | +<<<<<<< HEAD |
| 62 | +your current branch changes |
| 63 | +======= |
| 64 | +incoming branch changes |
| 65 | +>>>>>>> conflict-branch |
| 66 | +``` |
| 67 | +*Decide which changes to keep, remove the conflict markers, and save the file.* |
| 68 | + |
| 69 | +### Step 6: Stage and Commit Changes |
| 70 | + |
| 71 | +After resolving conflicts, stage the file: |
| 72 | +```bash |
| 73 | +git add example.md |
| 74 | +``` |
| 75 | +Commit the resolution: |
| 76 | +```bash |
| 77 | +git commit -m "Resolved merge conflict in example.md" |
| 78 | +``` |
| 79 | + |
| 80 | +### Step 7: Push Your Changes |
| 81 | + |
| 82 | +Push the updated branch to your fork: |
| 83 | +```bash |
| 84 | +git push origin <conflict-branch-name> |
| 85 | +``` |
| 86 | + |
| 87 | +### Step 8: Open a Pull Request |
| 88 | + |
| 89 | +1. Go to your fork on GitHub → Compare & Pull Request |
| 90 | + |
| 91 | +2. Reference the original issue in the PR description: |
| 92 | +```bash |
| 93 | +Closes #<issue-number> |
| 94 | +``` |
| 95 | +3. Submit the PR. Maintainers will review your changes and provide feedback if needed. |
| 96 | + |
| 97 | +## Tips: |
| 98 | +* Conflicts are normal; everyone faces them. |
| 99 | +* If the terminal seems hard to use, try GitHub Desktop or the VS Code Git extension. |
| 100 | +* Always check your changes with git status and git diff before you commit. |
| 101 | +* Keep your commit messages clear and descriptive. |
0 commit comments