无法配置 git 终端以推送已创建的项目

Unable to configure git terminal to push a already created project

我创建了一个项目并想将其推送到 git。我已经在 git 上创建了存储库,现在想推送我的代码,但我无法配置 git。当我尝试 运行 git push -u origin master 时出现以下错误 错误:

fatal: 'git@github.com/dearestpankaj:cbb6c2bc8c0ea84120749a745fe59ab5de04d8b6/CoffeeDbApp' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我已经使用以下命令添加了我的电子邮件和用户名:

git config --global user.email "my_email@gmail.com"
git config --global user.name "my_git_user_name"

之后我做了以下事情:

git init
git add -A
git commit -m 'my first commit'
git remote add origin git@github.com/my_git_user_name/MyRepositoryName

但是使用上面的命令我得到以下错误: 致命:远程源已经存在。

git push -u -f origin master

使用上面的命令,我得到了访问权限错误。 我知道我必须在某处添加我的密码,但我无法找到将它添加到我的终端的位置。 我现在还在 GitHub 设置中创建了一个个人令牌,但仍然不确定如何使用它。 现在我的远程只有 master 分支,这是默认创建的。我想推入这个分支,稍后会为我的工作添加更多分支。

编辑: 我尝试添加 SSH 密钥,但我仍然无法 push/pull。当我尝试 git 推送时,我得到以下信息:

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

当我尝试上述命令时,出现以下错误: 至 github.com:dearestpankaj/CoffeeDbApp.git

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:dearestpankaj/CoffeeDbApp.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.

以下是将计算机上存在的新代码库推送到 GitHub 的步骤:

  1. 创建 SSH 密钥:instructions
  2. 将刚刚创建的 SSH 密钥上传到 GitHub:instructions
  3. 从您的存储库中删除旧的 origin Git 远程:git remote remove origin
  4. 如果您还没有完成,请在 GitHub 上创建一个新存储库:instructions
  5. 在存储库的 GitHub 网站上,单击 Code 按钮,select Use SSH 如果可见,然后复制 URL .它应该以 git@github.com
  6. 开头
  7. 添加新的 origin Git 遥控器:git remote add origin [paste URL](将 [paste URL] 替换为您刚刚复制的 URL
  8. 运行 git push 推送到 GitHub

除了按照 Kevin 提到的添加 SSH 密钥外,还需要执行以下步骤:

git pull origin master --allow-unrelated-histories
git merge origin origin/master
... add and commit here...
git push origin master