5

Maybe a duplicate question, though I have tried to found out answers from existing questions but failed.

I created a git repo on the server with command:

mkdir gitrepo
cd gitrepo
git init

Then from another machine I tried to push files to this repo but failed.

git init
git clone user@server:~/gitrepo/.git
cd gitrepo
touch test
git add test
git commit -a

Util now, no error occurs. When I try to push the changes to the server, the following error occurs:

>git push
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'user@server:~/gitrepo/.git'

Anyone encountered this problem before?

I found an blog which explains well the difference between non-bare and bare repo. http://www.bitflop.com/document/111 Those who gets the same problem may refer to this.

cheng
  • 2,106
  • 6
  • 28
  • 36
  • 1
    Perhaps you should specify a branch such as 'master'. – Emily May 24 '12 at 15:18
  • I tried this "git push master", got "fatal: 'master' does not appear to be a git repository. fatal: The remote end hung up unexpectedly". Current I am on the master branch – cheng May 24 '12 at 15:23

3 Answers3

6

git push [remote-name] [branch-name]. e.g. git push origin master

Ulas Keles
  • 1,681
  • 16
  • 20
4

On the first machine, you created a non-bare repository, or a repository that has a working copy. Pushing to a non-bare repo can get a little exciting, so make sure that's actually what you want.

On the second machine, you created a new repository in the current directory (git init), then cloned gitrepo into a sub-directory as a second repo. Again, that's fine, just make sure it's what you wanted.

Here's how it would work with a bare repo on the first machine and one repo on the second:

First machine:

git init --bare gitrepo.git

Second machine:

git clone user@server:~/gitrepo.git
cd gitrepo
touch test
git add test
git commit -a

# '-u' tells git to track the remote master branch with your local master branch
git push -u origin master
ellotheth
  • 4,333
  • 2
  • 17
  • 29
0

refer to "Why can't I push to this bare repository?"

try doing: git push --set-upstream origin master

Community
  • 1
  • 1