创建私有仓库可以参考这篇文章的前面7步

关于Github私有仓库的创建

然后我想在私有仓库上传文件该怎么办呢?

在你的文件夹右键git bash

  1. 初始化git
git init
  1. 添加本地文件
git add .
  1. 上传本地
git commit -m "first commit"
  1. 设置branch(我仓库的branch是main,也有master的,根据实际情况修改就好了)
git branch -m main
  1. 远程连接
git remote add origin XXX

这里的XXX可以用https地址也可以用ssh地址,我用的是ssh地址,这里需要配置一下ssh keys,可以看这篇文章:GitHub 添加 SSH keys

在这里插入图片描述

  1. 推送到远程仓库
git push -u origin main

这一步我报错了

在这里插入图片描述

! [rejected] main -> main (non-fast-forward)

解决办法可以看github官方文档的解释:
github中文版文档:处理非快进错误
github英文版文档:Dealing with non-fast-forward errors

我使用的命令:

git fetch origin main
git merge origin FETCH_HEAD
git pull --rebase origin main

(还不太懂原理,后面继续学习一下)

有博客Git错误non-fast-forward的解决方法说:

git pull = git fetch + git merge FETCH_HEAD    
git pull --rebase =  git fetch + git rebase FETCH_HEAD 

稍微记录一下

  1. 继续推送
git push

又出错了: fatal: The current branch main has no upstream branch. To push the current branch and set the remote as upstream,

在这里插入图片描述
查看博客的方法

git push报错:The current branch master has no upstream branch

我也看看我有什么分支:

本地分支:

git branch

在这里插入图片描述

远程分支:

git branch -a

在这里插入图片描述
所以到底推送哪个呢?

这时由于远程仓库太多,且分支较多。在默认情况下,git push时一般会上传到origin下的master分支上,然而当repository和branch过多,而又没有设置关联时,git就会产生疑问,因为它无法判断你的push目标

解决方法(我使用的)

git push --set-upstream origin main

其他方法

git push -u origin main

这篇博客写得也很好,可以看看。
git push提示no upstream branch解决方案

完美解决!!!
在这里插入图片描述


其他参考

通过git把文件传到github的私有仓库里

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐