git - 远程添加来源与远程设置网址来源 [英] git - remote add origin vs remote set-url origin

查看:292
本文介绍了git - 远程添加来源与远程设置网址来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的存储库:

  git init 
echo#MESSAGE>> README.md
git add README.md
git commit -m第一次提交



然后我想把我的提交推送到在github上创建的空的远程仓库,所以我必须设置远程。



使用以下命令有什么区别? :

  git remote add origin git@github.com:User / UserRepo.git 
git remote set-url origin git@github.com:User / UserRepo.git

最后我执行push:

  git push -u原点大师

Edit1:

当我在git init之后调用远程set-url起源时会发生什么?远程设置网址原点是否创建原点?如果在git init之后,origin已经存在,那么在我的场景中使用这些命令没有什么区别,对不对?

解决方案

  git remote add origin git@github.com:User / UserRepo.git 

是用于添加新的远程

  git remote set-url origin git@github.com:User / UserRepo.git 

用于更改现有远程存储库的网址

  git push -u origin master 

会将您的使用 origin -u 定义远程存储库的master分支的代码,让您将当前的本地分支指向远程主分支



文档


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 git@github.com:User/UserRepo.git
git remote set-url origin git@github.com: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 ?

解决方案

git remote add origin git@github.com:User/UserRepo.git

is used to a add a new remote

git remote set-url origin git@github.com:User/UserRepo.git

is used to change the url of an existing remote repository

git push -u origin master

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

Documentation

这篇关于git - 远程添加来源与远程设置网址来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆