0

I cloned my repo on my laptop and followed the steps:

git add .

git commit -m "First commit"

git remote add origin (repository URL)

git push -u origin master

but for some reason, I get a fatal error telling me that the repo not found. What's the issue?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Sarvagya Gupta
  • 861
  • 3
  • 13
  • 28
  • maybe you mis-typed the repo address – Tamar Jun 20 '17 at 04:20
  • What is the exact text of the error? – OneCricketeer Jun 20 '17 at 04:20
  • If you cloned the repo from yourself, you did not need to add the origin – OneCricketeer Jun 20 '17 at 04:21
  • After adding the remote origin, run `git remote -v` to see if your remote git address(es) is/are listed. – MichaelSolati Jun 20 '17 at 04:24
  • Is it a private repo ? I f yes , try removing the remote origin and re-adding it with your username and password credentials on the repo URL – Always_Beginner Jun 20 '17 at 04:24
  • 2
    Possible duplicate of [Git Push ERROR: Repository not found](https://stackoverflow.com/questions/10116373/git-push-error-repository-not-found) – LuFFy Jun 20 '17 at 06:22
  • @MichaelSolati, This is what I get: `origin https://github.com/Flock1/Udacity/tree/master/Project%205 (fetch)` `origin https://github.com/Flock1/Udacity/tree/master/Project%205 (push)` – Sarvagya Gupta Jun 20 '17 at 13:15
  • Okay you're not pushing up to a git repo, your pushing up to the GitHub URL for viewing your repo. The repo URL should look like this `https://github.com/USERNAME/REPOSITORY.git` – MichaelSolati Jun 20 '17 at 13:18
  • @MichaelSolati, should I be doing something like this: `git remote add origin https://github.com/USERNAME/REPOSITORY.git` – Sarvagya Gupta Jun 20 '17 at 13:26
  • Yes, with username replaced with `Flock1` and REPOSITORY with `Udacity`. Based on your previous comments. – MichaelSolati Jun 20 '17 at 13:28
  • @MichaelSolati, got this: `fatal: remote origin already exists.` – Sarvagya Gupta Jun 20 '17 at 13:31
  • Because the `origin` was assigned to the wrong URL. Read this to remove the remote https://help.github.com/articles/removing-a-remote – MichaelSolati Jun 20 '17 at 13:38
  • @MichaelSolati, I removed it. Just one more question, I have folders in the repo. So how do I make sure that my files get uploaded to a specific folder? – Sarvagya Gupta Jun 20 '17 at 13:42
  • If you created the `git` repo in a root directory of all the folders, then all of your sub folders will be tracked just fine. – MichaelSolati Jun 20 '17 at 13:56
  • Got this after pushing: `error: failed to push some refs to 'https://github.com/Flock1/Udacity.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.` – Sarvagya Gupta Jun 20 '17 at 14:41
  • So your remote is ahead of your local. Run `git pull` and resolve any conflicts that may have occurred. You should be able to push up then. – MichaelSolati Jun 20 '17 at 14:48
  • @SarvagyaGupta I have updated my answer to take into account your last error message – VonC Jun 20 '17 at 14:49

2 Answers2

1

You can refer to the official GitHub "Error: Repository not found" listing the main reasons:

  • spelling
  • permissions
  • ssh access (that is, if you have used an ssh url)
  • existence of the repo

In your case, the origin url is wrong:

git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

In your case:

git remote set-url origin https://github.com/Flock1/Udacity.git

That won't change anything about the repo: you can add an push.

That is: you clone a full repo, not a folder within the repo.


error: failed to push some refs to 'https://github.com/Flock1/Udacity.git'  
  hint: Updates were rejected because the tip of your current branch is behind 
  hint: its remote counterpart

If your working tree is clean (meaning if git status reports there is no modification or untracked file), do:

git pull --rebase
git push

That will replay your commits on top of the updated upstream remote repo.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Checked everything. Repo exists and I have cloned the repo on my laptop. So i think I'm good there. – Sarvagya Gupta Jun 20 '17 at 13:27
  • If you have cloned the repo, you don't need the git remote add command. Check if you can push, assuming you are the owner of the repo. – VonC Jun 20 '17 at 13:28
  • When I said you don't need that command, I meant don't type it. If you do, you would get that error message. – VonC Jun 20 '17 at 13:33
  • Can't. It says reporistory not found: `fatal: repository 'https://github.com/USERNAME/REPO/tree/master/Project%205/' not found` – Sarvagya Gupta Jun 20 '17 at 13:35
  • @SarvagyaGupta never mind: I have seen the comments above: I have eidted the answer accordingly. – VonC Jun 20 '17 at 13:56
  • @SarvagyaGupta When you clone, make sure to clone the repo, not a folder within the repo. The proper url for a repo is `https://github.com/USERNAME/REPO`, not `https://github.com/USERNAME/REPO/tree/...`; this is Git, not Subversion. – VonC Jun 20 '17 at 13:56
  • When I run `git status`, I get the following in red color: `modified: solution (modified content)` – Sarvagya Gupta Jun 20 '17 at 16:23
  • @SarvagyaGupta yes, you need to add and commit your current modification, before the pull --rebase – VonC Jun 20 '17 at 16:28
0

After adding the remote origin, run git remote -v to see if your remote git address(es) is/are listed.

From there you should ensure that your remote origin url looks right. A remote url should look like https://github.com/USERNAME/REPOSITORY.git.

If you need to remove an incorrect origin and assign a new one you can remove that remote with the following command git remote rm origin

MichaelSolati
  • 2,847
  • 1
  • 17
  • 29
  • No need for rm/add: I have added the correct remote command in my answer. – VonC Jun 20 '17 at 14:20
  • @VonC Based my answer off of the convo I had with the OP in the comments of the question. – MichaelSolati Jun 20 '17 at 14:21
  • I know. I was having the very same conversion – VonC Jun 20 '17 at 14:46
  • So, something funny has happened. I followed your steps and for some reason, it pushed to github. When I checked, the commit is empty. Nothing got pushed for some reason. I'm trying to add files using `git add .` and when I check the status, I get this: `On branch master nothing to commit, working tree clean` – Sarvagya Gupta Jun 21 '17 at 04:37
  • In your root folder try `git status` and post back the results – MichaelSolati Jun 21 '17 at 04:39
  • `On branch git_fix` `Untracked files:` `(use "git add ..." to include in what will be committed)` `.gitignore` `Project 1/` `Project 2/` `Project 3/` `Project 5/.gitignore` `Project 5/Project 1/` `Project 5/Project 2/` `Project 5/Project 5/` `nothing added to commit but untracked files present (use "git add" to track)` – Sarvagya Gupta Jun 21 '17 at 07:24
  • It sounds as if you possibly have a git repo inside of another git repo, which is causing some of the confusion. Your nested repo hasnt had any changes hence the `On branch master nothing to commit, working tree clean`, but in the root folder you have the untracked files. – MichaelSolati Jun 21 '17 at 09:57