使用Visual Studio 2015提交后无法Push至Bitbucket分支求助
Alright, let’s tackle this non-fast-forward push error you’re hitting. This happens because someone (or another of your own sessions) has pushed new commits to the remote Test_Branch since you last pulled it down—your local branch is out of sync, so Git won’t let you overwrite those remote changes directly. Here’s how to fix it, both using the VS 2015 Bitbucket extension and a command line fallback:
Using Visual Studio 2015’s Bitbucket Extension
Follow these steps right in the IDE:
- First, make sure you’re on your local
Test_Branch(check the branch selector at the bottom right of VS; if not, click it and switch toTest_Branch). - Open the Team Explorer pane (you can hit
Ctrl+\, Ctrl+Mto toggle it), then go to the Sync tab. - Click the Pull button to fetch and merge the latest commits from the remote
origin/Test_Branchinto your local branch.- If you hit a conflict (VS will notify you), head back to the Changes tab. You’ll see the conflicting files marked with a red icon. Open each file, edit it to resolve the conflicting sections (look for
<<<<<<<,=======,>>>>>>>markers), then right-click the file and select Resolve Conflict > Mark as Resolved.
- If you hit a conflict (VS will notify you), head back to the Changes tab. You’ll see the conflicting files marked with a red icon. Open each file, edit it to resolve the conflicting sections (look for
- Once all conflicts are fixed (if any), go back to the Changes tab. If the merge created an automatic commit, you’re good to go—if not, you might need to commit the merge changes with a short comment like "Merge remote changes into Test_Branch".
- Finally, click Commit and Push again. This time, your local branch is synced with the remote, so the push should succeed.
Command Line Fallback (If the GUI Runs Into Issues)
If you prefer using Git commands, open Command Prompt (or Git Bash) and navigate to your local repo folder:
- Switch to your local branch:
git checkout Test_Branch - Pull the latest remote changes:
git pull origin Test_Branch- If there’s a conflict, open the conflicting files in your editor to fix them, then run
git add .to stage the resolved files, followed bygit committo finalize the merge.
- If there’s a conflict, open the conflicting files in your editor to fix them, then run
- Push your updated local branch:
git push origin Test_Branch
Quick Note
Always try to pull remote changes before starting your work if you’re collaborating with others—it helps avoid these sync issues in the first place. If you’re comfortable with Git rebasing, you could also use git pull --rebase origin Test_Branch instead of a regular merge to keep your commit history cleaner, but merging is safer for beginners since it preserves all commit context.
内容的提问来源于stack exchange,提问作者ASHISH_TECHIT

