0

I have a local git repo with some history.
I would like to add it to my remote git server:

# On my server, I create a remote repo
git init project.git --bare --shared

# On my local computer, I add the remote repo
git remote add origin user@server:/srv/git/projet.git

# Try to push
git push origin master
# error: src refspec master does not match any.
# error: failed to push some refs to 'user@server:/srv/git/projet.git'

# Try to pull
git pull origin master
# fatal: Couldn't find remote ref master
# fatal: the remote end hung up unexpectedly

If I clone the remote repo first, then copy the source code, I will lose the git history.
Anyone knows how to do it ?

Nicolas
  • 6,289
  • 4
  • 36
  • 51
  • Possible duplicate of [Git error: src refspec master does not match any](https://stackoverflow.com/questions/5802426/git-error-src-refspec-master-does-not-match-any) – phd Nov 28 '18 at 15:15
  • That is, you don't have branch `master` in the local repo because you haven't committed anything, and you don't have branch `master` in the remote repo because you haven't pushed anything. – phd Nov 28 '18 at 15:16
  • https://stackoverflow.com/search?q=%5Bgit%5D+%23+error%3A+src+refspec+master+does+not+match+any – phd Nov 28 '18 at 15:16

1 Answers1

1

I suppose you already manage correctly your repo locally (git add, commit and so on), so this probably doesn't work because on origin (your server) there is no branch master yet, as it is bare and you haven't cloned the repo from the server originally.

You should try

git push -u origin master

It should push and create the remote master branch as well

From the doc https://git-scm.com/docs/git-push#git-push--u

For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull[1] and other commands. For more information, see branch..merge in git-config[1].

davideSerafini
  • 246
  • 1
  • 6