Alex
Alex

Reputation: 44265

How to fix "fatal: remote origin already exists." on 'git remote add'?

I want to create a git repository on my USB stick. On the stick I created a bare git repository by using the command

git init --bare MyRepo

and in the repository on the laptop (Ubuntu 14.04) I issued the following commands

git init
git add .
git commit -m 'first commit'
git remote add origin /media/alexander/Stick/MyRepo

and got the error

fatal: remote origin already exists.

I successfully created a git repo on the stick just before without any error (using different directories of course). Now I get this error. The output of 'git status' is

On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

So what is going wrong?

Upvotes: 7

Views: 14351

Answers (2)

Ank_247shbm
Ank_247shbm

Reputation: 542

1. create new directory name similar to that created on github on your desktop
2. copy all the files and directory to the corresponding new directory

Commands:

git init

In case any error

git rm .git

Add all files to be pushed

git add .

Check if all pushed correctly

 git commit -m "Commit Done"

 git branch -M main

 git remote add origin https://github.com/ank247/cPeer.git
 git push -u origin main

 

Upvotes: 0

Sajib Khan
Sajib Khan

Reputation: 24136

Remove the remote origin first, then add again with the path.

$ git remote rm origin
$ git remote add origin <repo-url> 

Another way: Set the origin's url instead of adding.

$ git remote set-url origin <repo-url>

Upvotes: 21

Related Questions