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)
目录
相关文章
|
2月前
|
网络安全 开发工具 git
git修改提交路径以及强制提交——异常:error: remote origin already exists.与异常:error: failed to push some refs to的解决
git修改提交路径以及强制提交——异常:error: remote origin already exists.与异常:error: failed to push some refs to的解决
20 0
|
7天前
|
开发工具 git
完美解决git 执行git push origin master指令 报错command not found
完美解决git 执行git push origin master指令 报错command not found
13 0
|
存储 JavaScript 前端开发
细读 Git | 让你弄懂 origin、HEAD、FETCH_HEAD 相关内容
细读 Git | 让你弄懂 origin、HEAD、FETCH_HEAD 相关内容
3598 1
细读 Git | 让你弄懂 origin、HEAD、FETCH_HEAD 相关内容
|
2月前
|
开发工具 git
Git:error: remote origin already exists
Git:error: remote origin already exists
21 2
|
5月前
|
开发工具 git
git push origin master提交报错解决办法
git push origin master提交报错解决办法
76 0
|
5月前
|
开发工具 git
【Git】 git push origin master Everything up-to-date报错
【Git】 git push origin master Everything up-to-date报错
|
6月前
|
运维 Shell 开发工具
【Git异常】Push master to origin/master was rejected by remote
【Git异常】Push master to origin/master was rejected by remote
101 0
|
开发工具 git
git报错:usage: git remote remove <name>(使用git remote rm origin 报错)
git报错:usage: git remote remove <name>(使用git remote rm origin 报错)
98 0
|
存储 开发工具 git
git 删除远程分支报错error: unable to delete ‘origin/xxx‘: remote ref does not exist
git 删除远程分支报错error: unable to delete ‘origin/xxx‘: remote ref does not exist
227 0
git 删除远程分支报错error: unable to delete ‘origin/xxx‘: remote ref does not exist
|
开发工具 数据安全/隐私保护 git
git push -u origin main 报错 remote: Invalid username or password.
git push -u origin main 报错 remote: Invalid username or password.
155 0