bash 使用 Git 创建跟踪分支的简洁方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5615016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 23:46:12  来源:igfitidea点击:

Succinct way to create a tracking branch with Git

gitbashshell

提问by Ram Rachum

Today I had to work with a remote branch called origin/}__test_syntax_error_in_simpack_settings. I wanted to create a tracking branch for it.

今天,我不得不使用一个名为origin/}__test_syntax_error_in_simpack_settings. 我想为它创建一个跟踪分支。

I had to type:

我必须输入:

git branch }__test_syntax_error_in_simpack_settings origin/}__test_syntax_error_in_simpack_settings

I didn't have autocompletion on the first argument, only on the second. I don't like typing. Is there a faster way to do this? The main barrier is having to type the name of the new local tracking branch. Is there a way to tell Git, "create a tracking branch with the same name as origin/whatever?"

我在第一个参数上没有自动完成功能,只有在第二个参数上。我不喜欢打字。有没有更快的方法来做到这一点?主要障碍是必须输入新的本地跟踪分支的名称。有没有办法告诉 Git,“创建一个与 同名的跟踪分支origin/whatever?”

回答by KingCrunch

git checkout -t -b whatever origin/whatever

or short

或短

git checkout -t origin/whatever

Something to read: http://git-scm.com/docs/git-checkout

需要阅读的内容:http: //git-scm.com/docs/git-checkout

回答by sehe

I'd do this in bash:

我会在 bash 中这样做:

git branch {,origin/}}__test_syntax_error_in_simpack_settings

Sidenote: you seem to have very unusual branch names that might create problems in shells unless properly escaped. Consider renaming your branches, to save yourself some typing and problems the easy way (the lowhanging fruit :))

旁注:您似乎有非常不寻常的分支名称,除非正确转义,否则可能会在 shell 中产生问题。考虑重命名你的分支,以简单的方式为自己节省一些打字和问题(唾手可得的果实:))