git – remote add origin vs remote set-url origin
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
below is used to a add a new remote:
below is used to change the url of an existing remote repository:
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:Below will reinitialize your local repo; also clearing remote repos (ie origin):
Then below, will create ‘origin’ if it doesn’t exist:
Else, you can use the
set-url
subcommand to edit an existing remote:Also, you can check existing remotes with
Hope this helps!
If you don’t have a git repo already initiate one with
git init
git remote -v
Check if any remote already existsgit remote set-url origin git@github.com:User/UserRepo.git
to change the origingit remote add origin git@github.com:User/UserRepo.git
to set new origin for your repo.git push -u origin master
to push your code to remote and add upstream (tracking) reference to your remote branch.NOTE: If you use
-u
flag, its for upstream, it enables you to use simplygit pull
instead ofgit pull origin <branch-name>
in upcoming operations.If you have existing project and you would like to add remote repository url then you need to do following command
if you would like to add readme.md file then you can create it and add it using below command.
make your first commit using below command
Now you completed all local repository process, now how you add remote repository url ? check below command this is for ssh url, you can change it for https.
How you push your first commit see below command :