You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitBash推送至GitHub报错:Fatal: master cannot be resolved to branch

Fixing "Fatal: master cannot be resolved to branch" When Pushing to GitHub

Hey there! Let's work through this frustrating error you're hitting when trying to push your master branch to GitHub. Since you've already checked off the basics—logging into your account, setting your global Git config with name/email, committing all your changes, and confirming you're on the master branch—here are the most common fixes that should get you back on track:

1. Verify Your Branch & Remote Setup First

First, let's double-check what branches exist locally and remotely to rule out any mismatches:

  • Run git branch -a to list all local and remote branches. You should see master (local) and remotes/origin/master (remote) if the branch exists on GitHub.
  • If remotes/origin/master doesn't show up, that means the master branch hasn't been created on GitHub yet—we'll fix that in step 3.

2. Fix the Upstream Tracking Relationship

This error often happens when your local master branch isn't linked (tracking) to the remote origin/master branch. To set that up:

  1. Run this command to establish the tracking connection:
    git branch --set-upstream-to=origin/master master
    
  2. Once that's done, try pushing again with:
    git push
    

3. Push for the First Time (If Remote Branch Doesn't Exist)

If this is your first time pushing the master branch to GitHub (so remotes/origin/master doesn't exist yet), use the -u flag to create the remote branch and set up tracking in one go:

git push -u origin master

The -u flag tells Git to remember this upstream relationship, so future pushes can just use git push without extra arguments.

4. Refresh Your Remote Info

Occasionally, Git might have outdated info about your remote repository. Run this to fetch the latest remote branch data:

git fetch origin

Then try the push command again.

5. Double-Check Your Branch Name

It sounds silly, but typos happen! Run git branch to confirm your current local branch is indeed named master (note: GitHub uses main as the default branch for new repos these days—if your repo was created recently, you might need to replace master with main in all the commands above).

If none of these work, feel free to share the output of git branch -a and git remote -v and we can dig deeper!

内容的提问来源于stack exchange,提问作者Tawnwen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:31:01