我是新手代码,并且一直试图将文本文件推送到我在GitHub上的仓库,但我继续得到同样的错误。
当我使用git push时,我收到以下错误:
$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
然后我做git push --set-upstream origin master并得到这个回复:
$ git push --set-upstream origin master
To https://github.com/KMagrane/test-repo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/KMagrane/test-
repo.git'
hint: Updates were rejected because the tip of your current branch is
behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for
details.
所以我尝试了git pull origin master并得到了这个回复:
$ git pull origin master
From https://github.com/KMagrane/test-repo
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
所以我不知道还有什么可以尝试将文件推送到我的仓库。任何帮助将不胜感激!
答案 0 :(得分:1)
我怀疑您正在使用与远程master
分支或其存储库无关的本地存储库。我建议您将远程存储库克隆到某个新文件夹,而不是试图抢救当前的设置:
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
然后,检查master
分支:
git checkout master
最后,将文本文件复制到所需位置,执行git add
后跟git commit
,然后按:
git push origin master
答案 1 :(得分:-1)
请在git bash中使用此命令,克隆你的git repo。
git status
然后,如果您有未合并的文件,请使用
添加它们git add .
然后使用
提交它git commit -m "<comment to push>"
然后使用
git push origin <branch-name>
如果您仍然收到任何错误,请将其发回。