27

I recently set up a new account with github. I'm following a Rails tutorial from Michael Hartl online ( http://www.railstutorial.org/book#fig:github_first_page ) and followed his instructions to set up my git which were also inline with the setup instructions at github. Anyways, the "Next Steps" section on github were:

  mkdir sample_app
  cd sample_app
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:rosdabos55/sample_app.git
  git push origin master

I got all the way to the last instruction (git push origin master) without any problem. When I entered that last line into my terminal, however, I got this error message:

fatal: No path specified. See 'man git-pull' for valid url syntax.

What might I be doing wrong?

Here are the contents of .git/config (reconstructed by Jefromi from the output of git config -l pasted into a comment below):

[user]
    name = Ross
    email = [REDACTED]
[core]
    editor = gvim -f
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@github.com:
    fetch = +refs/heads/*:refs/remotes/origin/*
Carlos
  • 331
  • 6
  • 14
user306472
  • 363
  • 2
  • 8
  • 12
  • 1
    someone might want to consider redacting that email address – Mike Dinsdale Apr 13 '10 at 05:10
  • I'm having a similar problem and the answer below didn't resolve it for me. I copied and pasted the git URL from the GitHub repo, edited the .git/config and made sure it was correct, and I'm getting a "fast-forward" error: To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. – Elisabeth May 16 '12 at 00:15

4 Answers4

32

I've stated this in the comments to another answer, but it's really the answer (and I've edited the appropriate section of the comments into the question where it belongs).

The URL for the remote was not configured correctly, for whatever reason. It's set to "git@github.com:", which is clearly missing the path, producing precisely the error you see. You need to reconfigure it correctly. You could simply edit .git/config, changing the appropriate line to contain the path. Or you could do this:

git remote rm origin
git remote add origin 'git@github.com:rosdabos55/sample_app.git'

You almost certainly made some small typo or careless mistake when you added the remote the first time - perhaps you hit enter in the middle of it, perhaps you typed a space after the colon. (For some reason, git does not appear to throw an error when you provide an extra argument after remote add <name> <url> - it just ignores it.) The upshot is that you didn't actually run that command, and you added a remote with an incomplete URL.

Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • For others coming here, if you're just updating the base URL -- such as the hostname, protocol, or port number -- don't forget to add the specific git repo details at the end of the URL... – CivFan Jun 24 '22 at 16:52
2

edit the git config in your home directory

vi ~/.gitconfig

comment the below

#[remote "origin"]
#   url = git@#######D########################.git
# fetch = +refs/heads/*:refs/remotes/origin/*

save it.

The conflict happens between the git config in global the local [individual project level].

This solved the issue for me.

jww
  • 97,681
  • 90
  • 411
  • 885
1

You may need to git pull origin before you git push origin master.

Tim Snowhite
  • 3,736
  • 2
  • 23
  • 27
  • 2
    If you are pushing a new branch to a repository or pushing to a new repository you do not need to pull first. – Jamey Hicks Apr 14 '10 at 14:53
0

Can you post the output of git remote show?

It looks like something went wrong when you added your remote repository (git remote add origin git@github.com:rosdabos55/sample_app.git).

Benjamin Manns
  • 9,028
  • 4
  • 37
  • 48
  • 2
    @user306472 (OP): How about the output of `git remote show -n origin`? – Chris Johnsen Apr 12 '10 at 03:22
  • * remote origin URL: git@github.com: HEAD branch: (not queried) Local ref configured for 'git push' (status not queried): (matching) pushes to (matching) – user306472 Apr 12 '10 at 19:54
  • 1
    That remote URL appears to be missing the path to the repository - it's just got the user and host. Try re-adding the remote with the URL in quotes (although I've never seen a shell that requires you to quote a colon...). – Cascabel Apr 13 '10 at 04:19
  • can you post the contents of .git/config? (it's easier on the eyes to edit the question and add it there) – zetetic Apr 13 '10 at 04:24
  • @ Jefromi: It still replies 'remote origin already exists' @zetetic: If I type in git config -l, the out put is 'user.name=Ross user.email=ross.jett@gmail.com core.editor=gvim -f core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.origin.url=git@github.com: remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* ' – user306472 Apr 13 '10 at 04:31
  • @user306472: When I say re-add, I mean remove it and add it. Of course the remote exists. The problem is that it's been incorrectly configured. You can clearly see that in the config output you pasted - it says `remote.origin.url=git@github.com:`, completely missing the path that should've come after that. Clearly you didn't actually add the remote with that full URL. (If you like you can directly edit .git/config instead of `git remote rm origin; git remote add origin ...`) – Cascabel Apr 13 '10 at 04:36
  • @ Jefromi: I removed origin and then re-added w the URL in quotes and then tried git push origin master and everything worked out perfectly. Problem solved! I'm not sure why I had to put it in quotes, but I really appreciate your help. – user306472 Apr 13 '10 at 04:44
  • @user306472: I've posted that as an actual answer, with a suggestion as to what you may've done wrong. – Cascabel Apr 13 '10 at 04:45