如何使用git提取,检出和拉取一个命令行? [英] How done with git fetch, checkout and pull with one command line?

查看:383
本文介绍了如何使用git提取,检出和拉取一个命令行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次需要在本地测试团队成员代码时,我都会运行3条命令.

Every time I run 3 commands when I need to test my team member code on local.

喜欢:

git fetch remote_name branch_name 
git checkout branch_name
git pull origin master

git fetch remote_name branch_name && git checkout branch_name等...

由于通常在获取它之后,我们总是签入它,而不是我们需要从原始主数据库中拉出.如果我们可以运行一个命令来完成所有这些步骤,它将更快.

Because normally after fetch it we always checkout into it than we need pull from origin master. If we can run one command to done all those step it will faster.

git是否有解决此问题的命令?

Does git has a command to fix that?

推荐答案

如果您经常使用此命令组合,则可能需要按照@ElpieKay的建议将功能添加到您的shell中.例如,如果您使用bashdash,则将以下代码添加到~/.bashrc中将允许您键入foo remote_name branch_name,它等同于您的问题中的语句.

If you use this combination of commands often, you might want to add the function to your shell, as suggested by @ElpieKay. For example, if you use bash or dash, then adding the following code to your ~/.bashrc will allow you to type foo remote_name branch_name which will be equivalent to the statements in your question.

function foo {
    git fetch $1 $2 && git checkout $2 && git pull origin master
}

如果您愿意输入git foo remote_name branch_name,则可以创建多语句git别名,如

If you would rather type git foo remote_name branch_name, it is possible to create multi-statement git aliases as answered in this question.

这篇关于如何使用git提取,检出和拉取一个命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆