推动 GIT 和 Bitbucket

Push on GIT and Bitbucket

在我的桌面上,我有一个名为 azerty 的文件夹,在这个文件夹中我有一个名为 index.html 的文件。 在这个文件中,我写了 <h1>test</h1>.

在 Bitbucket 上,我必须创建我的存储库。我将此存储库命名为桌面上文件夹的名称,因此 azerty.

我的存储库已创建

现在,我打开 GIT bash。

这是我的步骤:

1- git init 
2- git clone https://Geek8006@bitbucket.org/Geek8006/azerty.git
3- git status

我不明白为什么,我的文件夹 azerty 中有一个新文件夹 azerty(在我的桌面上)?

然后...

4- git add . 
5- git status 
6- git commit -m "test" 

当我做最后一步时:

7- git push origin master

我有这个错误信息

$ git push origin master
fatal: 'origin' 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.

总而言之,我有两个问题:

1- 为什么我的桌面文件夹 azerty 中有一个新文件夹 azerty

2-

上有几个主题
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

在这里点赞 ->

但是,它不起作用。

非常感谢您的帮助。

当您克隆存储库时,Git 将其克隆到您已经初始化为另一个 Git 存储库的目录内的新文件夹 azerty 中。您应该使用 git clonegit init(稍后添加遥控器),但不能同时使用。

所以现在你有一个没有远程的初始化存储库,这就是为什么你得到 origin 不知道的错误。并且您在 azerty 文件夹中有一个克隆的存储库(带有远程)。

我建议您只删除两个本地存储库并从头开始。您可以通过将此作为参数传递给 git clone 来指定存储库应克隆到的目录。要使用当前目录,只需传递 ..

rm -rf ./.git                     # remove the .git folder
rm -rf ./azerty                   # remove the nested repository
git clone <repository> .          # clone into current directory
git add index.html
git commit -m "Add index.html"

无需克隆:您可以将对新远程存储库的引用添加到本地存储库:

cd C:\path\to\my\repo
git remote add https://url/new/repo
git push -u origin main

这样,您可以保留现有的本地存储库,并将其添加到远程源以供您推送内容。

确保先删除嵌套的克隆。

git remote -v //To check if anything is there in origin

如果没有就做

git remote add origin https://Geek8006@bitbucket.org/Geek8006/azerty.git


git remote -v //To check again if it is listed

在此之后,您可以提交并推送。

问题分析

使用这两个命令:

  1. git init
  2. git clone https://example.com/azerty.git

您正在创建两个 git 存储库。

  • 第一个(我称之为A),用init命令创建。
    • 为空
    • 在当前目录有他的root
    • 无出处
  • 第二个(我称之为B),使用clone命令创建。
    • 是远程存储库的克隆
    • 有源(远程存储库)
    • 他的根位于当前目录中创建的名为 azerty 的新目录中。 这就解释了为什么你有一个新的 azerty 目录。

Git 明确警告您(黄色提示)

you've added another git repository inside your current repository

因为它是用 init 创建的,A 没有来源。

当您尝试 push 时,您位于 A 的根目录中,因此您正在尝试 push A。由于 A 没有来源,push 失败。

解决方案

从头开始:

  • 将您的重要文件保存在临时文件夹中。
  • 在您希望 azerty 文件夹出现的位置使用 git clone
  • move 将您的文件放入 azerty 文件夹(或任何子文件夹)。
  • 使用:
    • git add .
    • git commit
    • git push

解决方案一:

git init 命令创建一个新的 Git 存储库。它可用于将现有的、未版本控制的项目转换为 Git 存储库或初​​始化一个新的空存储库。

请访问参考link

方案二:

发生该错误是因为未设置远程来源。 为了设置原点,您需要 运行 此命令。 [参考虚拟示例]

git remote add origin https://repositoryurlpath.git

虚拟示例

git add .
git commit -m "Your commit message"
git remote add origin https://repositoryurlpath.git
git push origin master

提前提示

检查是否设置了远程原点

git 远程-v

重置远程原点

git remote remove origin
git remote add origin https://repositoryurlpath.git