git可以知道您当前分支的哪个分支吗?

git可以知道您当前分支的哪个分支吗?

问题描述:

我想创建一个git别名,使我可以从分支的原始分支同步我的分支。

I'd like to create a git alias that lets me sync my branch from the original branch it was branched from.

例如,如果我从<分支A> ,是否有办法让git别名认识到它需要从 origin /<分支A> 以便同步?

For example, if I branched from <branch A>, is there a way for a git alias to recognize that it needs to pull from origin/<branch A> in order to sync?

Git不知道或不在乎分支名称,例如 master feature-31415 ourDevelopmentProcessUsesReallyLongBranchNamesBecauseWithHateUs ,来了它所知道或关心的只是该名称存在,并且当前指向某个特定的提交。也就是说,尽管每个分支都可以有一个上游设置。

Git does not know or care how a branch name, like master or feature-31415 or ourDevelopmentProcessUsesReallyLongBranchNamesBecauseTheyHateUs, came about. All it knows or cares about is that the name exists and currently points to some particular commit. That said, though, every branch can have one upstream setting.

如果运行 git merge 不带参数,或用作 git rebase的< upstream> 参数(如果不带参数运行),依此类推。通常, master 的上游是 origin / master 。您可以将 sbr (短分支)设置为上游有 origin / anotherLongNameBecause他们WantToReplaceUsWithRobots ,而不必再次键入。

The upstream that you configure is taken as the merge argument if you run git merge with no arguments, or to use as the <upstream> argument for git rebase if you run that with no arguments, and so on. Typically the upstream for master is origin/master. You could set sbr (short branch) to have origin/anotherLongNameBecauseTheyWantToReplaceUsWithRobots as its upstream, and never have to type that again.

origin / zorg 设置为 evil $ c $的上游c>:

git branch --set-upstream-to=origin/zorg evil

并删除上游:

git branch --unset-upstream evil

上游设置只是一个分为两部分的字段:

The upstream setting is simply a two-part field:

$ git config --get branch.master.remote
origin
$ git config --get branch.master.merge
master

这是 master 具有 origin / master 作为其上游。 1 git也自动使用上游,是 git push 的默认推送目标,并且是应用 @ {upstream} $的结果c $ c>至t他分公司的名字。这全部内置在Git中。问题是每个分支只能获得一个上游。

This is how and why master has origin/master as its upstream.1 The upstream is also used automatically by git status, and is the default push target for git push, and is the result of applying @{upstream} to the branch name. This is all built in to Git. The catch is that you get only one upstream per branch. If that's all you need, you are good.

您可以添加自己的配置项,例如: 2

You can add your own configuration items, e.g.:2

$ git config branch.master.zorblax giant-space-eel

,但是Git本身不会使用它。尽管如此,Git是一个巨大的工具集,而不仅仅是一个简化的解决方案,永远无法用于其开发人员无法想象的任何事情:您可以编写使用自己的代码c> zorblax 设置。

but nothing in Git itself will use this. Still, Git is a giant tool-set, not just a predigested solution that can never be used for anything outside the immediate imagination of its developers: you can write your own code that uses the zorblax setting, if you like.

1 您可以将本地分支设置为另一个本地分支的上游。在配置方面,这会将 remote 部分设置为,Git的其余部分在必要时将其忽略,例如,

1You can set a local branch as the upstream of another local branch. Configuration-wise, this sets the remote part to ., which the rest of Git then ignores when necessary, e.g., for showing the @{upstream} setting symbolically.

这里还有一个隐藏的细节,与分支有关,用于象征性地显示 @ {upstream} 设置。名称映射,当 remote 设置为远程名称时。这是因为 merge 设置的原始值早于遥控器的发明。

There is also a hidden detail here having to do with branch name mapping, when remote is set to the name of a remote. This is because the original value of the merge setting predates the invention of remotes. Normally this makes no difference, though.

2 总统佐伯(Jorblax)。注释漫画的日期,十多年前。我怀疑红色按钮的文字是较新的。...

2President Zorblax. Note date of comic, more than ten years ago. I suspect the red-button text is newer, though....