95

I am following the instructions given here to create a Git repository. All went well until the last line:

$ git push -u origin master  

fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

I'm using git version 1.7.11.3 on OS X 10.6.8

$ git remote -v  

returns nothing

Config file for the repository:

[core]
repositoryformatversion = 0  
filemode = true  
bare = false
logallrefupdates = true  
ignorecase = true  

I've had to open sudoers file using sudo visudo command and add the following to it (under # User privilege specification):

git ALL=(ALL) ALL.  

Now if I do:

$ git remote add origin /Volumes/500GB/git-repository/myproject.git  

it comes back with no error, but I don't see any code in the repository (it has the aforementioned directories like branches, hooks, ...)

If I do:

$ git push -u origin master  
fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

$ git remote -v   
origin /Volumes/500GB/git-repository/myproject.git (fetch)     
origin /Volumes/500GB/git-repository/myproject.git (push)
Michael
  • 8,362
  • 6
  • 61
  • 88
Al Lelopath
  • 6,448
  • 13
  • 82
  • 139

14 Answers14

89

As it has already been mentioned in che's answer about adding the remote part, which I believe you are still missing.

Regarding your edit for adding remote on your local USB drive. First of all you must have a 'bare repository' if you want your repository to be a shared repository i.e. to be able to push/pull/fetch/merge etc..

To create a bare/shared repository, go to your desired location. In your case:

$ cd /Volumes/500gb/   
$ git init --bare myproject.git

See here for more info on creating bare repository

Once you have a bare repository set up in your desired location you can now add it to your working copy as a remote.

$ git remote add origin /Volumes/500gb/myproject.git

And now you can push your changes to your repository

$ git push origin master
Community
  • 1
  • 1
ro ko
  • 2,906
  • 3
  • 37
  • 58
37

Here are the instructions from github:

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/tqisjim/google-oauth.git
git push -u origin master

Here's what actually worked:

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/tqisjim/google-oauth.git
git clone origin master

After cloning, then the push command succeeds by prompting for a username and password

Sunny Jim
  • 585
  • 5
  • 13
29

Most likely the remote repository doesn't exist or you have added the wrong one.

You have to first remove the origin and re-add it:

git remote remove origin
git remote add origin https://github.com/username/repository
fredmaggiowski
  • 2,232
  • 3
  • 25
  • 44
wanderlandderek
  • 376
  • 4
  • 5
12

Your config file does not include any references to "origin" remote. That section looks like this:

[remote "origin"]
    url = git@foo.com:repository.git
    fetch = +refs/heads/*:refs/remotes/origin/*

You need to add the remote using git remote add before you can use it.

che
  • 12,097
  • 7
  • 42
  • 71
  • In git, you push because you want to get your code to some other repo than the one you're working on. If all you want to do is have a local git repository you are already done. If you want something alse you might want to check out some tutorial explaining remote and local repos, possibly starting from here: http://git-scm.com/book/en/Getting-Started-Git-Basics – che Mar 15 '13 at 19:13
  • I want to have 2 copies of the code. One on the harddrive of the mac (Working directory) and one on the external USB drive (Git directory). If I have 2 copies of the code with the steps I have taken (ie all but the last one in the original post), then I am done.But I don't see any source code on the external USB Drive. I see a directory structure with directories like branches, hooks, info, objects, refs, but no source code. – Al Lelopath Mar 15 '13 at 19:46
  • Well, if you're missing the remote repo, you probably didn't do the `git remote add` part in the guide you originally linked. Anyway, if you successfully push to another repository, it will not automatically do a checkout, you'd have to do that manually in the repo (but you don't have to, because the files will still be in git structures there). See also this answer: http://stackoverflow.com/a/1887474/7806 – che Mar 15 '13 at 20:36
6

When you create a repository in bitbucket.org, it gives you instructions on how to set up your local directory. Chances are, you just forgot to run the code:

git remote add origin https://username@bitbucket.org/username/reponame.git

Roman
  • 8,826
  • 10
  • 63
  • 103
5

May be you forgot to run "git --bare init" on the remote? That was my problem

user3353537
  • 161
  • 2
  • 3
5

I'll still share my short answer humbly, knowing that I'm super late to answer this question.

Here's, a simple and clean explanation that solved my issue

Also, since I was using the SSH key I used the following command:

  • $ git remote add origin git@github.com:{your-username}/{your-remote-repo-branch}

for instance it would look like:

  • $ git remote add origin git@github.com:aniketrb-github/microservices.git

If you are using the HTTPS URL, refer to the answer provided by @sunny-jim above.

Do correct me if I'm wrong. Thanks.

Aniket
  • 303
  • 5
  • 11
3

my case was a little different - unintentionally I have changed owner of git repository (project.git directory in my case), changing owner back to the git user helped

khd
  • 31
  • 1
3

If you are on HTTPS do this-

git remote add origin URL_TO_YOUR_REPO
Hitesh Roy
  • 31
  • 2
2

I had this problem cause i had already origin remote defined locally. So just change "origin" into another name:

git remote add originNew https://github.com/UAwebM...

git push -u originNew

or u can remove your local origin. to check your remote name type:

git remote

to remove remote - log in your clone repository and type:

git remote remove origin(depending on your remote's name)

Vasyl Gutnyk
  • 4,813
  • 2
  • 34
  • 37
2

To resolving this problem.I just create a new folder and put some new files.Then use these commond.

* git add .
* git commit 
* git remote add master `your address`

then it tells me to login in. To input your username and password. after that

git pull 
git push origin master

finished you have pushed your code to your github

Eric Chao
  • 858
  • 7
  • 8
2

Here is how I resolved this issue

Go to the remote repository on Github and copy the project's repository url.

On git bash type: git remote add origin the remote repository url goes here

1

Setting remote repository URL worked for me:

git remote set-url origin https://github.com/path-to-repo/MyRepo.git

Rajesh Swarnkar
  • 601
  • 1
  • 6
  • 18
1

See this is the issue we get because either your repo is not accessible from the CLI or You are not authorized to do that 2nd case is simple you simply request the access then you will able to do that. for the 1st case if git push origin <private_branch_name> is not working then it will give the solution in the CLI itself Just follow with just one step:

  1. git remote add <name> <URL> . enter image description here <URL> can be accessed using the UI of Gitlab/Github -> clone -> copy https. link and then
  2. git push origin <private_branch name> Now raise the MR. Refer Image.