这是来自StackOverflow上的提问:
When I run:
git push origin branchnameWhat 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)