带上-u 参数其实就相当于记录了push到远端分支的默认值,这样当下次我们还想要继续push的这个远端分支的时候推送命令就可以简写成git push即可。
如果从未设置过 push 的 -u 选项(之前的每一次 push 都使用 远程别名(可以通过 git remote -v 来查看远程别名)和分支名)而省略远程别名和分支名,则会报错:
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin main
网友评论