2

In my desktop, I have a folder named azerty, into this folder I have a file named index.html. Into this file, I wrote <h1>test</h1>.

enter image description here

On Bitbucket, I have to create my repository. I named this repository like the name of the folder which is on my desktop, so azerty.

enter image description here

My repository is created

enter image description here

Now, I open GIT bash.

Here are my steps:

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

enter image description here

I don't understand why, I have a new folder azerty into my folder azerty (in my desktop)?

enter image description here

Then...

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

enter image description here

When I do the last step:

7- git push origin master

enter image description here

I have this error message

$ 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.

In summary, I have 2 problems:

1- Why I have a new folder azerty into my folder azerty in my desktop ?

2- There are several subjects on the

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

like here -> Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository."

But, it does not work.

Thank you a lot for your help.

joel
  • 255
  • 1
  • 10
  • 3
    Whilst helpful context, please don't include images of text in questions, _just put the text_. It's easier to read, and doesn't prevent visually impaired readers from seeing the question. – AD7six Jun 03 '21 at 09:15
  • @AD7six: Ah! Sorry... – joel Jun 03 '21 at 18:34

5 Answers5

4

No need to clone: you can add to your local repopsitory a reference to your new remote repository:

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

That way, you keep your existing local repository, and add it a remote origin for you to push your content.

Make sure to delete your nested clone first.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    This way, the nested repository is still committed in the outer repository. I don't think that @joel intended to have a nested repository that points to the same remote. – Matt Jun 03 '21 at 09:27
  • 1
    @Matt I would delete the nested clone first indeed. – VonC Jun 03 '21 at 09:28
  • 1
    I think that OP did not realize that there is a nested clone. – Orace Jun 03 '21 at 09:35
  • 1
    @Orace Yes, but no need to restart from scratch: delete the nested folder, add the remote, and push. – VonC Jun 03 '21 at 09:39
  • 1
    `give a man a fish and you feed him for a day ...`. You are right. As I guess OP is a newbie in git, I think it's also good to show OP the correct way to do it from the start point not the _current_ mess OP is now. Anyway it's better to show both and our answers are complementary on this point. – Orace Jun 03 '21 at 09:52
  • Thank you very much for your explanations. – joel Jun 03 '21 at 18:36
3

When you cloned your repository, Git cloned it into a new folder azerty inside the directory that you already initialised as another Git repository. You should use either git clone or git init (and add a remote later) but not both.

So now you have an initialised repository without a remote which is why you get the error that origin is not know. And you have a cloned repository (with a remote) inside the azerty folder.

I recommend that you just delete both local repositories and start from scratch. You can specify the directory that a repository should get cloned into by passing this as an argument to git clone. To use the current directory, simply pass a ..

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"
Matt
  • 12,848
  • 2
  • 31
  • 53
3

Problem analysis

With those two commands:

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

You are creating two git repository.

  • The first one (I will call it A), created with the init command.
    • Is empty
    • Has his root in the current directory
    • Has no origin
  • The second one (I will call it B), created with the clone command.
    • Is a clone of a distant repository
    • Has an origin (the distant repository)
    • Has his root located in a new directory named azerty created in the current directory. That explain why you have a new azerty directory.

Git warn you explicitly about that (yellow hint)

you've added another git repository inside your current repository

Since it has been created with init, A doesn't have an origin.

When you try to push you are in the root directory of A so you are trying to push A. Since A doesn't have an origin, the push fail.

Solution

Restart from scratch:

  • Save your important files in a temporary folder.
  • Use git clone where you want the azerty folder to appear.
  • move your files into the azerty folder (or any sub folder).
  • Use:
    • git add .
    • git commit
    • git push
Orace
  • 7,822
  • 30
  • 45
2
git remote -v //To check if anything is there in origin

If there is nothing then do

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


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

After this, you can commit and push.

2

Solution 1:

The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository.

Please visit for reference link.

Solution 2:

That error occurred because it's remote origin is not set. In order to set the origin you need to run this command. [refer dummy example]

git remote add origin https://repositoryurlpath.git

Dummy example

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

Tips ahead

Check if the remote origin is set

git remote -v

Reset the remote origin

git remote remove origin
git remote add origin https://repositoryurlpath.git
Erielama
  • 111
  • 1
  • 3