cheng
cheng

Reputation: 2136

Failed to pushing files into newly created git repo

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.

Upvotes: 5

Views: 15158

Answers (3)

user3159604
user3159604

Reputation: 11

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

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

Upvotes: 0

ellotheth
ellotheth

Reputation: 4513

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

Upvotes: 4

Ulas Keles
Ulas Keles

Reputation: 1781

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

Upvotes: 6

Related Questions