DEV Community

Cover image for What happens when you add a wrong "remote origin URL" to your GitHub project?
Kemigisa Lailah Grant
Kemigisa Lailah Grant

Posted on

What happens when you add a wrong "remote origin URL" to your GitHub project?

I must mention, this just happened to me this evening on Tuesday 11th February 2020 and I spent about 15 minutes or so working on that.

A friend has been asking me for some code that was just locally on my PC, so after he persisted, I just realised all I could do is put it on Github for him to find.

For those that don't know how to push a local project to GitHub, hopefully, these following can help:-

  1. Go to your GitHub account on your browser, login(if you aren't logged in).
  2. Create a repository with the same name as that of your local project e.g cats
  3. Open your terminal & browse to your project directory e.g
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ 
Enter fullscreen mode Exit fullscreen mode

then do the following commands

git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/lailahgrant/cats.git
git push -u origin master
Enter fullscreen mode Exit fullscreen mode

Now back to our main question!!!
let's say
instead of the above, you end up doing the following,

git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/lailahgrant/cat
git push -u origin master
Enter fullscreen mode Exit fullscreen mode

I know this can happen because it happened to me today and this is what I did :-

lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git remote add origin https://github.com/lailahgrant/ikowap
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git push -u origin master
Username for 'https://github.com': lailahgrant
Password for 'https://lailahgrant@github.com':
remote: Repository not found.
fatal: repository 'https://github.com/lailahgrant/ikowap/' not found
Enter fullscreen mode Exit fullscreen mode

Then after realising my mistake, I now tried to put the correct URL and I got the following errors:-

lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git remote add origin https://github.com/lailahgrant/ikowapi.git
fatal: remote origin already exists.
Enter fullscreen mode Exit fullscreen mode

At this point I was so desperate & I tried every solution in the --help but all in vain.

I finally got a solution from the popular saviour - Stack overflow and all I did was run the following:-

lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git remote rm origin
Enter fullscreen mode Exit fullscreen mode

The above command removed all the remote origin URLs I had put.

Now it was safe for me to run the other commands...

lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git remote add origin https://github.com/lailahgrant/ikowapi.git
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git push -u origin master
Username for 'https://github.com': lailahgrant
Password for 'https://lailahgrant@github.com': 
Counting objects: 185, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (180/180), done.
Writing objects: 100% (185/185), 1005.56 KiB | 3.63 MiB/s, done.
Total 185 (delta 32), reused 0 (delta 0)
remote: Resolving deltas: 100% (32/32), done.
To https://github.com/lailahgrant/ikowapi.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ 
Enter fullscreen mode Exit fullscreen mode

Hopefully you found this helpful, Thanks for reading through

Top comments (11)

Collapse
 
dorothykiz1 profile image
dorothykiz1

Thanks for this..

Collapse
 
lailahgrant profile image
Kemigisa Lailah Grant

🤗🤗🤗thank you everyone for your feedback. I’m humbled. 🎈🎈

Collapse
 
fannynyayic profile image
Fanny Nyayic

Thank you!

Collapse
 
phyllisnabangi profile image
Phyllis Nabangi

Perfect👌🏾

Collapse
 
cnkesiga profile image
Bill Clinton #MP - 🇺🇬

Awesome 🎉

Collapse
 
joelcrawford14 profile image
Joel Crawford

Thanks for that

Collapse
 
stuartelimu profile image
stue

Wow, this could happen to anyone, thanks a bunch .

Collapse
 
lailahgrant profile image
Kemigisa Lailah Grant

You’re welcome dear, thanks for your time

Collapse
 
amkayondo profile image
Kayondo Edward

Awesome lilian 🤾‍♀️🎉🎉

Collapse
 
livmadrid profile image
Olivia Boynton

THANK YOU!

Collapse
 
vladislav67 profile image
Владислав

Спасибо, помогло