3

I was trying this:

mkdir ~/gitremote
cd ~/gitremote
git init --bare

I can see file names like

HEAD        config      hooks       objects
branches    description info        refs

OK, then in another directory,

git clone trosky@localhost:/Users/trosky/gitremote
vi readme (add one line)
git add .
git commit -m "1st file"
git push origin master

Then it gives an error:

$git push origin master
error: src refspec master does not match any.
error: failed to push some refs to 'trosy@localhost:/Users/trosky/gitremote'

I searched google and it says this kind of error is due to empty folder on remote repo. But the remote repo is not empty, and locally I'm committing a file that's not empty either. Why this error still prompts out?

How to fix it? Thanks.

Hugo y
  • 1,421
  • 10
  • 20
Troskyvs
  • 7,537
  • 7
  • 47
  • 115
  • what's the OS? If it's MAC, please use 'git clone /Users/trosky/gitremote` instead. If it's windows please use git clone `C:/\Users/\trosky/\gitremote` instead if you are windows user. And you can use `git remote -v` to check whether the path is correct. – Marina Liu Dec 26 '16 at 07:13
  • Thanks Marina, your "git clone" suggestion will work wish git push, but the remote repo seems not receiving any new file. I'm on MAC, but what's the difference between 'git clone /Users/trosky/gitremoe' and 'git clone 'trosy@localhost:/Users/trosky/gitremote'? – Troskyvs Dec 26 '16 at 07:59
  • @Troskyvs, I answered as below, please check the commit sha-1 in remote folder. – Marina Liu Dec 26 '16 at 08:31

2 Answers2

4

Try with the syntax:

git push -u origin master

Since you are pushing to an empty repo, you need to explicitly push master.
Otherwise, the default push.policy being simple, Git would look for a branch named master in your remote repo (and since your remote bare repo is empty, it has no master branch yet)

Of course, you won't see any readme in your remote bare repo, since it is a bare repo: no working tree.

what's the difference between 'git clone /Users/trosky/gitremoe' and 'git clone 'trosy@localhost:/Users/trosky/gitremote'

One is using the file protocol also called local protocol, the other ssh protocol. You don't need ssh here.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, but I still got the same problem: $git push -u origin master error: src refspec master does not match any. error: failed to push some refs to 'x@localhost:/Users/trosky/gitremote' – Troskyvs Dec 26 '16 at 07:49
  • @Troskyvs are you in the `gitremote` folder of your cloned repo? (and not in `/Users/trosky/gitremote`). What `git status` returns? – VonC Dec 26 '16 at 07:53
  • Well, I just checked, yes, you're to the point of checking SHA-1 under my bare repo of refs/heads/master file. – Troskyvs Dec 26 '16 at 08:45
0

You can use git clone /Users/trosky/gitremote instead.

git clone /Users/trosky/gitremote is used the local protocol. Because your remoterepo is on your local PC, so the local protocol is suitable and fast.

git clone 'trosy@localhost:/Users/trosky/gitremote' is used scp to transfer data which mainly used for different devices data transfer.

After you push to remote repo, you may go to the remote repo folder but not find the pushed file. But it’s actually exist. Because bare repo has not working directory. It’s stored in /Users/trosky/gitremote/objects. And you can check the commit SHA-1 in /Users/trosky/gitremote/refs/heads/master is in accordance with local repo.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74