【问题标题】:git push/pull origin [branch] shortcut?git push/pull origin [branch] 快捷方式?
【发布时间】:2018-07-05 16:14:01
【问题描述】:

在过去的几个月里,我一直在控制台中使用 git,我觉得打字有点太多了。

这是我的流程(假设我在 foo 分支):

[ ... working ... ]
git add .
git commit -m "Commit message"
git pull origin foo
git push origin foo

我知道这是第一世界的问题之一,但有没有办法在这里减少打字?例如,我可以只使用git pullgit push 吗? git pushgit push origin foo 有什么区别?

【问题讨论】:

  • 别忘了配置和使用 bash 命令行补全。
  • 我设置了别名,gphgit pushgagit add

标签: git push commit


【解决方案1】:

对于git push,可以使用配置自动推送到与本地同名的远程分支。

git config push.default current

https://git-scm.com/docs/git-config#git-config-pushdefault

对于git pull,您需要将本地分支跟踪分支到远程分支。

参考https://stackoverflow.com/a/19279975/1433665

【讨论】:

  • 引用的so问题是the参考,对我来说。
【解决方案2】:
git commit -am 'subject: research the commands, Luke!'
git push

是等效的,除非您自己添加了新文件,因此您需要告诉 Git 搜索它们并使用 git add . 跟踪它们,或者 git push 在您正在跟踪的远程分支上看到您没有跟踪的新历史记录'不知道,所以你需要先拉。

【讨论】:

    【解决方案3】:

    实际上不是“捷径”,但确实减少了打字量:

    曾经:
    git push --set-upstream origin foo

    然后:
    git pushgit pull

    【讨论】:

    • 我不明白这个工作流程,我已经做了一段时间了,但是如果你有很多分支,很容易忘记设置上游。
    • 好的,我明白你的意思。也许您可以在 ~/.bashrc 中使用别名,例如 alias gplo="git pull origin"alias gpho="git push origin",以免破坏现有工作流程。
    猜你喜欢
    • 1970-01-01
    • 2013-05-04
    • 1970-01-01
    • 2017-11-14
    • 2017-08-19
    • 1970-01-01
    • 2012-04-17
    • 2018-09-30
    • 1970-01-01
    相关资源
    最近更新 更多