只需一个命令即可获取并签出远程git分支 [英] fetch and checkout a remote git branch in just one command
本文介绍了只需一个命令即可获取并签出远程git分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果
- 我有已设置了远程
$REMOTE
的本地存储库 - 和一个新分支
$BRANCH
存在于我尚未获取的远程仓库中
- I have local repo with a remote
$REMOTE
already set up - and a new branch
$BRANCH
exists on the remote repo that I haven't fetched, yet
我可以获取该分支并通过单个命令将其检出到具有相同名称的跟踪本地分支吗?
can I fetch that branch and check it out into a tracking local branch of the same name in a single command?
我可以通过两个命令使用
git fetch $REMOTE $BRANCH
git checkout $BRANCH # or more explicitly git checkout -b $BRANCH $REMOTE/$BRANCH
或(受问题
or (inspired by this answer to Question How do I check out a remote Git branch?) with
git fetch $REMOTE $BRANCH:$BRANCH
git branch --set-upstream-to=$BRANCH $BRANCH
推荐答案
没有内置命令,但是您可以在~/.gitconfig
中定义别名:
There is no builtin command, but you could define an alias in your ~/.gitconfig
:
[alias]
fetch-checkout = !sh -c 'git fetch $1 $2 && git checkout $2' -
这篇关于只需一个命令即可获取并签出远程git分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文