9

I'm in the master branch and have added the remote branch, after which I'm unable to push the data from local to remote.:

$ Git remote add master https://....git

$ Git push origin master https:// ...git
Fatal: invalid refspec 'https://...git'
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
melony_r
  • 177
  • 1
  • 1
  • 8

3 Answers3

9

You should "git remote add" origin, not master:

git remote add origin https://...
git remote remove master
git push -u origin master

If you already add a remote origin, then fix it with git remote set-url, instead of git remote add:

git remote set-url origin https://...
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I tried this. but I got the "error: remote origin already exists". How do I solve this ? –  Jan 31 '23 at 09:40
  • @VedantKakade Good point. I have edited the answer to address that use case. – VonC Jan 31 '23 at 12:34
1

My problem was solved by changing the authentication method from HTTPS to SSH.

Guide for Github SSH keys: https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

Create a new SSH key in github (https://github.com/settings/keys)

jeppoo1
  • 650
  • 1
  • 10
  • 23
0

I had similar problem with gitlab and what helped me in this case, was adding additional option --push-option=ci-skip and putting at the end HEAD:<branchname> like below

git checkout -b ${newbranch}
#..<do  your stuff>..
#..<add and commit>...
git push --push-option=ci-skip http://${SERVER_HOST}/${PROJECT_PATH}.git/ HEAD:${newbranch}
mati kepa
  • 2,543
  • 19
  • 24