Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git - remote add origin vs remote set-url origin

Tags:

git

github

I create a new repository:

git init echo "# MESSAGE" >> README.md git add README.md git commit -m "first commit" 

Then I want to push my commit to the empty remote repository created on github so I have to set remote.

What is difference between using following commands ? :

git remote add origin [email protected]:User/UserRepo.git git remote set-url origin [email protected]:User/UserRepo.git 

At the end I perform push:

git push -u origin master 

What happens when I call git remote set-url origin just after git init? Does git remote set-url origin create origin? If origin already exists after git init there is no difference between using those commands in my scenario, right?

like image 957
Irbis Avatar asked Mar 16 '17 09:03

Irbis


People also ask

What is git remote add origin URL?

To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at. The git remote set-url command changes an existing remote repository URL. So basicly, remote add is to add a new one, remote set-url is to update an existing one.

What is origin in git remote add origin?

The origin RemoteWhen you clone a repository with git clone , it automatically creates a remote connection called origin pointing back to the cloned repository. This is useful for developers creating a local copy of a central repository, since it provides an easy way to pull upstream changes or publish local commits.

What is the difference between origin and remote in git?

A remote is just a word: a name to use to identify some other Git repository somewhere. The string origin is the default name of the (singular) remote that git clone puts in automatically, when you clone from some other ("origin"-al) Git repository. You can choose some other name, and/or add more remotes.

What is remote URL in git?

Git remote is an important part of Git, a tool that provides an easy-to-use system for tracking changes in source code during software development. With Git, you can save the state of your code at regular intervals (determined by you).


1 Answers

below is used to a add a new remote:

git remote add origin [email protected]:User/UserRepo.git 

below is used to change the url of an existing remote repository:

git remote set-url origin [email protected]:User/UserRepo.git 

below will push your code to the master branch of the remote repository defined with origin and -u let you point your current local branch to the remote master branch:

git push -u origin master 

Documentation

like image 53
Shubham Khatri Avatar answered Oct 12 '22 23:10

Shubham Khatri