git:fatal the current branch master has no upstream branch

英文解决方案连接,感谢michaeltwofishGoZonerdunni

git本地仓库push远程仓库的时候,报了异常:fatal the current branch master has no upstream branch

但是按提示, git push --set-upstream ../remote-jackygit.git master 并没有解决问题。

经过查询发现目前有两种解决方案:

1.翻译后大致意思是,远程仓库创建时候要建立一个README文件,然后再进行push操作。因为这个文件是远程仓库主分支所必须的,见如下截图。

Create the repo on github; add a README file on github and then clone the github repository.  Creating the README file (or any file actually) is needed in order to get a master branch.Notice how github prompts for creating a README when creating a repository:

2.翻译后大致意思是,如果不想重新创建远程仓库再克隆(针对方案1),或者初始化本地仓库,可以使用下面命令: git push -u origin master,其中origin 表示远程仓库名称,master是远程仓库的push目标分支。-u (推测为update缩写^_^~)表示本地分支将建立对远程仓库目标分支的检测,如果远程仓库目标分支不存在,将新建分支再push;如果存在,将进行push更新。

Instead of creating a new repository on Github, cloning that, or reinitializing your local repository, the following command would have been sufficient:

git push -u origin master

origin stands for the remote name (default is origin), and master is the branch you want to push, in your case it's master, otherwise you would have to change that in the command.
-u means, that your local branch will be setup to track the new created master branch on the origin repository (the master on the origin will be the upstream branch of your local branch). If the branch master doesn't exist on the remote repository, it will be created, otherwise it will be updated (the -u works no matter if it exists or not).

然后,验证此方法,确实可行!

 

 

这个错误信息表示当前的分支master没有上游分支(remote branch)。为了推送当前分支并将远程仓库设置为上游分支,可以使用以下命令: git push --set-upstream origin master 这个错误通常出现在使用git init初始化本地仓库后,通过git remote add origin添加远程仓库地址,然后使用git push进行推送时。原因是没有将远程分支设置为当前分支的上游分支。 解决方法如下: 1. 首先,使用git fetch命令将远程仓库的最新数据拉取到本地仓库。 2. 然后,使用git checkout -b master origin/master命令将远程仓库的主分支拉取到本地并设置为本地仓库的主分支。 此时,本地仓库的数据已经与远程仓库同步,就好像使用git clone命令一样。接下来,你就可以使用git add、git commit和git push命令来添加、提交和推送数据了。 综上所述,解决这个问题的步骤如下: 1. 使用git fetch命令将远程仓库的最新数据拉取到本地仓库。 2. 使用git checkout -b master origin/master命令将远程仓库的主分支拉取到本地并设置为本地仓库的主分支。 3. 使用git add、git commit和git push命令来添加、提交和推送数据。 这些是今天使用到的一些Git指令。你可以使用git branch命令查看分支,使用git checkout命令切换到已有分支或新分支,使用git status命令显示当前项目状态,使用git commit命令提交项目到本地仓库,使用git push命令将本地仓库分支推送到远程仓库并建立分支,使用git merge命令更新分支(合并分支)。 希望这些信息对你有帮助!
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值