melony_r
melony_r

Reputation: 177

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

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'

Upvotes: 9

Views: 41314

Answers (5)

MNR
MNR

Reputation: 1

git push --set-upstream origin branch

Upvotes: 0

user2394284
user2394284

Reputation: 6028

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.

Upvotes: 0

VonC
VonC

Reputation: 1324917

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://...

Upvotes: 9

mati kepa
mati kepa

Reputation: 3201

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}

Upvotes: 0

jeppoo1
jeppoo1

Reputation: 698

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)

Upvotes: 1

Related Questions