What is “origin” in Git?

这是来自StackOverflow上的提问:

When I run:

git push origin branchname

What exactly is origin and why do I have to type it before the branch name?

我来将其保存到墙内。


一句话概括:origin是你的系统上对于某个特定的远程(GitHub)仓库的别名。

它不是某个仓库的真实属性。

当你执行下面操作时,意思就是推送到origin仓库,你不需要输入仓库的真实地址,而且也可以不使用origin这个别名。请接着看。

git push origin branchname

从这里可以看到别名以及对应的真实地址:

MacBook-Pro:LeetCode-Solution nomasp$ git remote -v
origin  https://github.com/NoMasp/LeetCode-Solution.git (fetch)
origin  https://github.com/NoMasp/LeetCode-Solution.git (push)

所以你也可以通过这种方式来推送提交:

git push git@github.com:git/git.git master

你也可以对这个alias来重命名:

MacBook-Pro:LeetCode-Solution nomasp$ git remote rename origin mynewalias
MacBook-Pro:LeetCode-Solution nomasp$ git br --all
* master
  remotes/mynewalias/HEAD -> mynewalias/master
  remotes/mynewalias/master

重命名之后:

MacBook-Pro:LeetCode-Solution nomasp$ git remote -v
mynewalias  https://github.com/NoMasp/LeetCode-Solution.git (fetch)
mynewalias  https://github.com/NoMasp/LeetCode-Solution.git (push)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值