1

I have created an empty git repository by use of gitolite and cloned it to my laptop. Usually, I can add files to it on my laptop on and push them to the repo but now an error occurs:

user@laptop Myproject % git clone newergit:Repo-Myrepo
Cloning into 'Repo-Myrepo'...
warning: You appear to have cloned an empty repository.
user@laptop Myproject % cd Repo-Myrepo
user@laptop Repo-Myrepo % vi test.txt
user@laptop Repo-Myrepo % git add test.txt 
user@laptop Repo-Myrepo % git commit -m "add test file to repo"
[main (root-commit) 27aa970] add test file to repo
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt
user@laptop Repo-Myrepo % git push origin master
error: src refspec master does not match any
error: failed to push some refs to 'newergit:Repo-Myrepo'

This used to work in the past but newly I am experiencing this error and don't know how to proceed?

jos
  • 83
  • 1
  • 6
  • Run a `git status` and a `git branch -al` and add it? You may find that the default branch is now `main` not `master` – GregHNZ Jan 29 '23 at 08:13
  • Unfortunately, git branch -al did not resolve the problem - I obtain the same error message as before. – jos Jan 29 '23 at 09:10

1 Answers1

0

Unfortunately, git branch -al did not resolve the problem

A git branch -avv is only there to list the local and remote branches, for you to understand which branch was created (locally by your git commit and remotely by Gitolite)

If you use Git 2.37+, you can activate the

git config --global push.autoSetupRemote true

From there, a simple git push (without any additional parameter) should be enough. It will pick the right branch name (the current one) and push it to the remote with remote tracking.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I have tried ```git config --global push.autoSetupRemote true``` but the same error message appears: ```user@laptop Repo-Myrepo % git push origin master error: src refspec master does not match any error: failed to push some refs to 'newergit:Repo-Myrepo'``` – jos Jan 30 '23 at 09:22
  • @jos The idea with that configuration is to then just use `git push`. If, however, the error message persists, you should edit your question with the output of `git status` and `git branch -avv`. – VonC Jan 30 '23 at 09:27
  • Great, I have executed ```git push``` instead of git ```git push origin master``` and now it works. Thank you, you have saved my day! – jos Jan 30 '23 at 10:06
  • @jos Great, well done! A `git push` will pick up the current branch. – VonC Jan 30 '23 at 10:06