Git push command, error encountered -fatal: invalid refspec 'https://github.......git'
Asked Answered
P

4

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'
Predicable answered 26/10, 2019 at 7:57 Comment(0)
G
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://...
Geer answered 26/10, 2019 at 8:12 Comment(2)
I tried this. but I got the "error: remote origin already exists". How do I solve this ?Lucic
@VedantKakade Good point. I have edited the answer to address that use case.Geer
T
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)

Twelfthtide answered 27/5, 2020 at 9:4 Comment(0)
E
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}
Everybody answered 16/5, 2022 at 7:35 Comment(0)
T
0

I think I found a bug in git: Trying to push a branch that ends with ".lock" also fails with "invalid refspec":

git push --force-with-lease HEAD~21:refs/heads/add-cargo.lock
fatal: invalid refspec 'HEAD~21:refs/heads/add-cargo.lock'
git push --force-with-lease HEAD~21:refs/heads/add-cargo-lock
…
remote: Create a pull request for 'add-cargo-lock' on GitHub by visiting …
 * [new branch]            HEAD~21 -> add-cargo-lock

Other file extensions work, so this is a bit inconsistent. Git version 2.45.2.

Timpani answered 17/6 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.