0

I am working locally an I have my origin repo called "example" (this repository was created from scratch). I cloned it into "clone_example". Both have only one branch, called master.

When making a change to my clone_example's master branch and try pushing it to origin, everything works fine. I'm using:

git push origin master

When I make a change on my master branch in my origin repo and try pushing it to the clone, I get this error.

fatal: 'clone_example' 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.

The code I'm using is:

git push my_clone master

I'm following a tutorial and although I followed all the steps in there, I got this error. I also tried the command "git init" on my clone repo, but I still get this Error.

I am using Bash for Ubuntu fr Windows, can it have anything to do with this? Thx.

Kasia
  • 118
  • 3
  • 16
  • Possible duplicate of [How do I do an initial push to a remote repository with Git?](https://stackoverflow.com/questions/2337281/how-do-i-do-an-initial-push-to-a-remote-repository-with-git) – Tim Biegeleisen Dec 12 '17 at 09:14
  • I already found that theread but I coudln't make a connection. I'm not working with a server... maybe it's my still poor understanding of Git but I can't see the similarity. – Kasia Dec 12 '17 at 09:16
  • What is `my_clone` vs. `clone_example`? – Oliver Charlesworth Dec 12 '17 at 09:52
  • @OliverCharlesworth from the documentation I understand that the name we give to the cloned repo when we're creating the connection doesn't have to be identical with the directory's name? In any case, the Error Git throws specifies "clone_example" and not "my_clone", when saying is not a git directory, so I assumed the connection is correct. – Kasia Dec 12 '17 at 10:53
  • I guess what I'm asking is, did you ever do `git remote add ...` in the original repo, and with what alias? Reps don't automatically know anything about their clones. – Oliver Charlesworth Dec 12 '17 at 10:54
  • Yes, I did. When using "git remote" I see origin is associated with the clone and the other way around. – Kasia Dec 12 '17 at 11:00

1 Answers1

-1

fatal: 'clone_example' does not appear to be a git repository

Looks like you did not init your folder as git repository, you mentioned you started from scretch.

git init

will do the work.

regarding the second part:

fatal:Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

Verify that you do have a remote with:

git remote -vv

If you dont see any output, create a remote repo on your server and than add it to your local repo as remote

# map remote repository to your local repository
git remote add origin <url>

If you are using ssh as your remote url you will have to add your ssh key to your server as well if its not there yet

# create ssh key
ssh-keygen

# copy the key into our server settings 
# (depend upon your server where to paste the key )
# assuming using defaults:
cat ~/.ssh/id_rsa.pub 
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 1
    If it weren't already a Git repo, then the OP wouldn't have been able to clone it. – Oliver Charlesworth Dec 12 '17 at 09:18
  • He mentioned in the q:`this repository was created from scratch` – CodeWizard Dec 12 '17 at 09:20
  • @CodeWizard I did init my origin as a git repository. I also used git remote and I do have a connection with clone_example (I named it my_clone). That's why I don't understand why it's not working. – Kasia Dec 12 '17 at 09:23
  • 1
    I assume that means "with git init locally" vs. cloning it from a remote server. – Oliver Charlesworth Dec 12 '17 at 09:50
  • 1
    Also, the solution to this problem doesn't need to involve a remote server (although I agree that having a central repo *normally* makes more sense from a workflow perspective). – Oliver Charlesworth Dec 12 '17 at 09:50
  • @OliverCharlesworth I am not using a server, indeed. For the purpose of the tutorial I am using a simple directory (let's say it's called Zero) where I created the origin directory and cloned it inside the same directory (Zero). So now I have 2 directories, inside the Zero directory. One is the origin and one is the clone and I'm trying to play with the Git commands in order to learn them. I have no idea how an ssh key would fit in this scenario. Or maybe I'm missing something. – Kasia Dec 12 '17 at 10:50