【问题标题】:Unable to push the existing code to a new git repository无法将现有代码推送到新的 git 存储库
【发布时间】:2018-12-14 22:46:31
【问题描述】:

我有来自项目的git 存储库我删除了.git 文件。现在我创建了一个新的 git 存储库并尝试将代码推送到新的存储库中。为此,我使用了命令

  1. git 初始化
  2. git 添加。
  3. git commit -m ""
  4. git远程添加源https://github.com/xxxx/project-sp.git
  5. git push -u origin master

对于第 5 点,错误为

xxx/project-sp.git 的权限拒绝给 xxxx。致命:无法访问“https://github.com/xxx/project-sp.git/”:请求的 URL 返回错误:403

然后我从凭据管理器中删除了 git 凭据并使用了命令git pull 我收到的消息是

warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/xxx/project-sp
 * [new branch]      master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

我应该怎么做才能将代码推送到新的 git 存储库。我对 git 很陌生。我该如何解决这个问题?

更新:当我尝试使用命令 git push --set-upstream origin master 时,我收到一个错误,因为

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/xxx/project-sp.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

【问题讨论】:

  • 你确定你可以访问这个仓库吗?您是否尝试过配置 RSA 密钥?
  • 是的,当我使用 cmd git push 时,我已经登录了。什么是 RSA 密钥我是 git 环境的新手。

标签: git github


【解决方案1】:

您可以按照 git 或 bitbucket 的文档来执行此操作。这是适用于 me 的文档链接

【讨论】:

  • 我遵循了相同的步骤,但是当我尝试推送错误消息时出现错误。
  • 您是否按照“help.github.com/articles/…”中的步骤操作
  • yes 在我们使用 git push origin 的时候,我遇到了错误。我已经更新了问题,请查看。
  • 请按照“stackoverflow.com/questions/7438313/…”的步骤操作
  • 请更新 git 配置文件中的 url 并使用 -f 标志提交
猜你喜欢
  • 1970-01-01
  • 2021-09-11
  • 2011-12-09
  • 2011-09-20
  • 1970-01-01
  • 2011-03-14
  • 1970-01-01
  • 2016-06-27
相关资源
最近更新 更多