What is “origin” in Git?

简介: 版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/71246537 ...
+关注继续查看
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/71246537

这是来自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)
目录
相关文章
|
6天前
|
开发工具 git
|
7天前
|
开发工具 git
git 的三剑客
git 的三剑客
7 0
|
21天前
|
Linux 项目管理 开发工具
如何优雅地使用git?
如何优雅地使用git?
|
1月前
|
存储 Linux 开发工具
git相关总结大全
git相关总结大全
|
3月前
|
存储 Java Linux
Git 2.41 is here!
* Git 作为一个开源项目刚刚发布了 [2.41 版本](https://lore.kernel.org/git/xmqqleh3a3wm.fsf@gitster.g/ "2.41 版本"),其中共有 95 位开发者贡献了新的特性以及已有缺陷的修复,而他们中的 29 位是新的贡献者。我们上次聊到 Git 的最新发布动态是在[Git 2.40 版本](https://github.blog/202
|
7月前
|
关系型数据库 MySQL 应用服务中间件
Git相关知识
Git相关知识
91 0
|
8月前
|
安全 程序员 开发工具
|
11月前
|
开发工具 git
git简单总结
git简单总结
|
11月前
|
缓存 JSON Linux
|
开发工具 git Windows
Git的使用
Git的使用
83 2
相关产品
云迁移中心
相关实验场景
更多
推荐文章
更多