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?
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.
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.
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.
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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With