如何使用git确定特定分支的点(origin // ????)

时间:2022-08-11 07:20:57

On some development branches I need to use origin/master on others I need to use origin/dev. I want to use some scripts to automate my work a little more, and I would like to know how to determine the origin string to use without having to pass it in as a parameter or have it set as an environment variable.

在一些开发分支上,我需要在其他人使用origin / master,我需要使用origin / dev。我想使用一些脚本来自动完成我的工作,我想知道如何确定要使用的原始字符串,而不必将其作为参数传递或将其设置为环境变量。

Using 'git remote show origin' gives me a bunch of output with the information I need near the end. It says:

使用'git remote show origin'为我提供了一堆输出,其中包含了我需要的信息。它说:

Local branch configured for 'git pull': mybranch merges with remote dev

为'git pull'配置的本地分支:mybranch与远程dev合并

Is there some way to do this without having to parse through all of the output for 'git remote show origin'?

有没有办法做到这一点,而不必解析'git remote show origin'的所有输出?

2 个解决方案

#1


0  

git branch -vv will give you a list of your local branches: name, current commit sha, and then in square brackets the name of the remote branch they're tracking (if any). You should be able to use that easily to find out what you need. Note that the active (currently checked out) branch is hilighted with a leading asterist (*).

git branch -vv将为您提供本地分支的列表:name,current commit sha,然后在方括号中,它们跟踪的远程分支的名称(如果有)。您应该能够轻松地使用它来找出您需要的东西。请注意,活动(当前已检出)分支是使用前导星号(*)进行的。

You can additionally limit the list by using git branch -vv --list <pattern> where <pattern%gt; would be the branch name you want to query (e.g. git branch -vv --list issue12 to get the info only for branch "issue12")

您还可以使用git branch -vv --list 来限制列表,其中 %gt;将是您要查询的分支名称(例如,git>

#2


0  

In the examples below I've set up a local branch develop, tracking the branch develop on the remote origin.

在下面的例子中,我设置了一个本地分支开发,跟踪远程源上的分支开发。

The easiest is to use git config to get this:

最简单的方法是使用git config来获取:

$ git config branch.develop.remote
origin

Under water, it's in .git/config. E.g.

在水下,它是在.git / config。例如。

[branch "develop"]
    remote = origin
    merge = refs/heads/develop

#1


0  

git branch -vv will give you a list of your local branches: name, current commit sha, and then in square brackets the name of the remote branch they're tracking (if any). You should be able to use that easily to find out what you need. Note that the active (currently checked out) branch is hilighted with a leading asterist (*).

git branch -vv将为您提供本地分支的列表:name,current commit sha,然后在方括号中,它们跟踪的远程分支的名称(如果有)。您应该能够轻松地使用它来找出您需要的东西。请注意,活动(当前已检出)分支是使用前导星号(*)进行的。

You can additionally limit the list by using git branch -vv --list <pattern> where <pattern%gt; would be the branch name you want to query (e.g. git branch -vv --list issue12 to get the info only for branch "issue12")

您还可以使用git branch -vv --list 来限制列表,其中 %gt;将是您要查询的分支名称(例如,git>

#2


0  

In the examples below I've set up a local branch develop, tracking the branch develop on the remote origin.

在下面的例子中,我设置了一个本地分支开发,跟踪远程源上的分支开发。

The easiest is to use git config to get this:

最简单的方法是使用git config来获取:

$ git config branch.develop.remote
origin

Under water, it's in .git/config. E.g.

在水下,它是在.git / config。例如。

[branch "develop"]
    remote = origin
    merge = refs/heads/develop