失败后自动将正确的CLI命令复制到剪贴板

时间:2018-01-12 21:57:01

标签: bash git

假设我跑:

git push

我收到错误消息:

fatal: The current branch cdt-rd has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin cdt-rd

有没有办法将我的git或bash联合起来,以便自动将正确的命令(git push --set-upstream origin cdt-rd)复制到我的剪贴板?

2 个答案:

答案 0 :(得分:1)

创建智能别名可能更容易,我使用这个:

git config --global alias.pto '!bash -c "git push --set-upstream ${1-origin} $(git symbolic-ref --short HEAD)" -'

默认情况下推送到原点git pto或其他远程git pto remote

它会自动解析当前分支名称,然后将分支推送到远程并设置上游。如果您已经设置了上游,则使用此命令而不是push也可以。

答案 1 :(得分:0)

git config --global push.default current

您只需要执行一次。然后,

git push
相关问题