New User: Unable to Push File

Hello Gitworld,

I’m a new user to both Ubuntu Linux (WSL) and Github, so bear with me.

So far I’ve setup my account, added my SSH key and I’ve authenitcated in my WSL terminal.

I wanted to try out pushing and pulling, so I created a new directory and created a new Git instance locally, then created a basic readme.txt within said directory. I created a repository on GitHub with the same name as the local directory (instance).

Now the issue… I connected my local repository to the remote one:

git remote add origin

but when I push:

git push origin master

I recieve this error message:

git: ‘remote-https’ is not a git command. See ‘git --help’.

I’m not sure what the error is, since I’m not using a ‘remote-http’ command at all in the line?

Any guidance would be much appreciated, thank you in advance.

Sounds like you made a mistake when you did your git remote add origin <git_uri>

Try git remote -v and see if it is as expected.

1 Like

when I try git remove -v it gives:

git: ‘remove’ is not a git command.

“remote” with a T :wink:

1 Like

oh jeez… thank you.
output:
origin https://github.com//heelo-world.git (fetch)
origin https://github.com//heelo-world.git (push)

I removed my username between the URL and .git file, but both were identical. Is that to be expected?

Yes, in most cases push and pull URLs for a remote are the same. However you mentioned wanting to use SSH authentication. To do that you need to change the URL to the SSH URL.

You can find the URL using the green “Code” button on your repository page and selecting SSH:
grafik

Then use git remote set-url origin SSH_URL to update the URL.

2 Likes

I removed my username between the URL and .git file, but both were identical. Is that to be expected?

Yes, but not if you plan to use SSH.

You should git remote remove origin then git remote add origin git@github.com:<owner>/<repo>.git. (@airtower-luna pointed out where to copy the SSH URL)

1 Like

There’s no need to remove the remote though, you can just change the URL. :wink:

1 Like

You mean if you just do an add with a colliding name it’ll replace the URL? I’ve never tried.

No, you can change the URL of the existing remote:

git remote set-url origin URL_GOES_HERE

There are also options to change e.g. just the push URL, but I don’t see a need for that here.

3 Likes

Oh okay, I see what you’re getting at. Thanks!

2 Likes

Thank you @kingthorin & @airtower-luna! Appreciate all the replies and help. I had a feeling I had to use the SSH URL, but wasn’t sure. I found a solution in the end by switching to it, but everytime I used:

git push origin master

I would get the error:

error: src refspec master does not match any
error: failed to push some refs to ‘github.com:CodezHere/heelo-world.git’

When I used:

git push origin

It worked!
What is the difference between the two? Am I losing anything by not being able to run the “git push origin master” command?

1 Like

The difference is with git push origin master you explicitly tell git to push the master branch to a matching remote ref, without it some defaults apply. I can’t guess why that form didn’t work, there are a lot of configuration option that affect what exactly might get pushed how, see the git push documentation. Common use is to set an upstream branch for branches you commonly push so git knows what to do on git push without any options.

1 Like