Mac Git新手求助:本地合并development分支并创建无冲突GitHub PR
Hey there, fellow Mac Git user! Let’s walk through this process step by step to get your feature branch prepped for a clean pull request. Since you’ve already committed all your local changes, we’re good to jump right in.
1. Confirm You’re on Your Feature Branch
First, make sure you’re working in the right branch. Run this command to switch to your feature branch (if you aren’t already there):
git checkout feature/my-feature-1
To double-check which branch is active, use:
git branch
Your current branch will be marked with an asterisk (*).
2. Update Your Local development Branch
Before merging, we need to pull the latest changes from the remote development branch to your local copy. This ensures you’re merging the most up-to-date code:
git checkout development git pull origin development
This syncs your local development branch with what’s live on GitHub.
3. Merge Updated development into Your Feature Branch
Switch back to your feature branch and merge the fresh development changes into it:
git checkout feature/my-feature-1 git merge development
4. Resolve Merge Conflicts (If They Pop Up)
If Git spots conflicting code between your feature branch and development, it’ll pause the merge and list the files with conflicts. Here’s how to fix them on Mac:
- Use a visual merge tool (recommended): Run
git mergetool– this will open Mac’s built-inopendifftool (or any other merge tool you’ve configured). It shows your branch’s changes on the left,development’s on the right, and lets you pick which lines to keep (or combine them manually). - Manual editing: Open the conflicting file in your code editor. Look for markers like:
Edit the file to resolve the conflict, then delete the marker lines. Save the file when done.<<<<<<< HEAD // Your feature branch's code ======= // development branch's code >>>>>>> development
Once you fix a conflicted file, stage it with:
git add <path-to-conflicted-file>
Repeat this for all conflicted files. When everything’s staged, finish the merge with:
git commit
Git will auto-generate a merge commit message – you can keep it or tweak it to add context, then save and close the editor to finalize the commit.
Pro tip: If you get stuck and want to cancel the merge entirely, run git merge --abort.
5. Push Your Feature Branch to GitHub
Now that your feature branch is synced with development and conflict-free, push it to the remote repository. If this is your first time pushing this branch, use:
git push --set-upstream origin feature/my-feature-1
The --set-upstream flag links your local branch to the remote one, so future pushes can just use git push.
If you’ve pushed this branch before, a simple git push will work.
6. Create a Conflict-Free PR on GitHub
Head over to your repository on GitHub. You’ll see a prominent banner prompting you to "Compare & pull request" for your newly pushed branch. Click that, then:
- Set the base branch to
development - Set the compare branch to
feature/my-feature-1 - Review the changes to confirm everything looks right (since you resolved conflicts locally, GitHub should show "No conflicts")
- Add a clear title and description for your PR, then click "Create pull request"
That’s it! Your PR is ready for review, with no conflicts to slow things down.
内容的提问来源于stack exchange,提问作者hotmeatballsoup

