Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+4 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

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

Edit1:

What happens when I call remote set-url origin just after git init? Does 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?

1 Answer

+4 votes
by (27.5k points)
edited by

Use the following command to add a new remote:

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

Use the following command to change the url of an existing remote repository:

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

Use the following code in order to 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

For more information here is an awesome tutorial for git:

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...