What is “origin” in Git?

Posted nomasp

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)

以上是关于What is “origin” in Git?的主要内容,如果未能解决你的问题,请参考以下文章

git checkout 报错 refname 'origin/branch-name' is ambiguous

Git Error: warning: refname 'origin/branch-name' is ambiguous.

What is a bare git repository?

What is Git? The 5 Minute Tutorial.

What is “:-!!” in C code?

ERRORS: ?: (corsheaders.E013) Origin '*' in CORS_ORIGIN_WHITELIST is missing scheme or netlo