git err :: 无法创建远程/分支

问题描述

我无法推送到我的 github。 我已经在github上上传了其他项目。 但突然出现问题。

在终端中,我运行以下:

1. git clone https://github.com/(username)/(reponame).git  
2. create remote to my github repogisry address.
3. git init  
4. git add .
5. git commit -m "message"
6. git push <repo> <branch>

但是有这个消息

"Cant's push refs to remote,Try running 'pull' to integrate your changes.

所以我拉->

git pull <remote name> <branch>

但还有其他错误

fatal: Couldn't find remote ref master

我检查了我的文件夹。 在 .git/refs 中没有包含远程分支的“remotes”文件夹。 但是在 VSCODE 中(当我运行 push to 时)有我/已经创建的弹出窗口。
解决这个错误删除remote,重新创建,再次git init,重启vscode, 但错误没有修复。

为了测试另一个,我创建了另一个项目,不同的 github repo。 这个项目有效。(在这个项目的文件夹中,remotes 文件夹在 refs 中)

但是之前出现的项目问题还是有错误

如何解决这个问题?请帮忙..

解决方法

克隆一个git-repo然后添加一个新的远程分支的步骤如下:

  1. git clone https://server.name/git/testing.git
  2. git checkout -b <branch-name> # create locally branch and checked out
  3. git push <remote-name> <branch-name> # push local branch to remote

所以不要在克隆后创建 new git repo (git init),因为 git clone 在他的工作流中创建了一个 git init Do I need to do 'git init' before doing 'git clone' on a project

也看看这个documentation