git push -u origin 和 git push --set-upstream origin 有什么区别

发布于 2025-01-10 00:22:39 字数 953 浏览 0 评论 0 原文

我正在学习如何使用 git,我需要从主 github 存储库进行克隆,对其进行分支,进行更改,然后将分支推送到 github 存储库 - 但我发现自己对最好的方法有点困惑就是这样。我知道 git 网上有很多资源,但我找不到一个正是这个问题的资源(尽管如果我错了,我很乐意使用它)。

我一直在我自己的私人 github 存储库上进行测试以查看差异,但似乎没有任何差异。

  1. 从存储库克隆。
git clone [email protected]:organization/repo
  1. 创建一个新分支
git checkout -b newbranch
  1. 进行更改、添加和提交,
touch file
git add file
git commit -m "added file"
  1. 当我尝试推送没有上游分支时
git push 

,我收到一条错误消息“致命:当前分支 newbranch 没有上游分支。 要推送当前分支并将远程设置为上游,请使用 git push --set-upstream origin newbranch

但我也看到很多在线教程使用 git push -u origin newbranch

这之间有什么功能上的区别吗?我确信网上有一些关于差异的资源,但 git 对我来说有点令人困惑,我想我会直接问这个问题来看看人们的想法。

I'm learning how to use git and I need to clone from a master github repo, branch it, make changes, and push the branch to the github repo - but I'm finding myself a bit confused on what the best way to do that would be. I know there are so many resources on git online but I can't find one that is this exact problem (although happy to use that if I'm wrong).

I've been testing on my own private github repo to see the differences and there doesn't seem to be any.

  1. clone from repo.
git clone [email protected]:organization/repo
  1. create a new branch
git checkout -b newbranch
  1. make changes, add, and commit
touch file
git add file
git commit -m "added file"
  1. when I try to push there is no upstream
git push 

I get an error saying "fatal: The current branch newbranch has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin newbranch

but I also see a lot of online tutorials using
git push -u origin newbranch

Is there any functional difference between this? I'm sure there is some resource online about the difference, but git is a bit confusing to me and I though i'd ask this one direct question to see what people thought.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玻璃人 2025-01-17 00:22:39

它们是完全一样的东西。 Unix 命令的许多选项都有短形式和长形式。您可以通过运行 git help push 来亲自查看这一点。

       -u, --set-upstream
           For every branch that is up to date or successfully pushed, add
           upstream (tracking) reference, used by argument-less git-pull(1)
           and other commands. For more information, see branch.<name>.merge
           in git-config(1).

They're exactly the same thing. Lots of options to unix commands have both a short and a long form. You can see this for yourself by running git help push.

       -u, --set-upstream
           For every branch that is up to date or successfully pushed, add
           upstream (tracking) reference, used by argument-less git-pull(1)
           and other commands. For more information, see branch.<name>.merge
           in git-config(1).
顾挽 2025-01-17 00:22:39

当您设置上游(或跟踪)分支时,您可以简单地执行拉取和推送,而无需使用 -u 而不是 --set-upstream 指定目标分支。 Git 自动知道它必须将新提交获取到远程跟踪分支。

这是一篇关于它的文章 此处

When you set your upstream (or tracking) branches, you can simply execute pulls and pushes without having to specify the target branch using -u instead of --set-upstream. Git automatically knows that it has to fetch the new commits to the remote tracking branch.

Here's an article about it here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文