
git本地分支和远程分支
Git branches provides very useful way to work with a project in multi developer mode. Every developer can use different or his branch to implement new features and then merge them into a main branch. In this tutorial we will learn how to list and print branch information.These branches can be local or remote too.
Git分支提供了一种在多开发人员模式下使用项目的非常有用的方法。 每个开发人员都可以使用不同的分支或分支来实现新功能,然后将它们合并到主分支中。 在本教程中,我们将学习如何列出和打印分支信息,这些分支也可以是本地或远程的。
打印/显示当前分支 (Print/Show Current Branch)
First step to get or list branch is printing or showing current branch. We will use just git branch
command which will list all branches. But current branch will be denoted with the asterisk *
. In this example master
is our current or working branch.
获取或列出分支的第一步是打印或显示当前分支。 我们将只使用git branch
命令,它将列出所有分支。 但是当前分支将用星号*
表示。 在此示例中, master
是我们当前的或正在工作的分支。
$ git branch

列出当地分支机构(List Local Branches)
Actually we have all ready listed local branches in previous example but in order to express the current working branch I do not provide this information. So we can list all local branches with the git branch
command. In most cases there will be more than one branch.
实际上,在前面的示例中,我们已经准备好列出所有本地分支,但是为了表示当前的工作分支,我没有提供此信息。 因此,我们可以使用git branch
命令列出所有本地分支。 在大多数情况下,会有多个分支。
$ git branch

列出所有远程分支(List All Remote Branches)
Up to now we have worked with the local branches but also remote branches are important part of the distributed software development because other developers will push their branches and this will be remote branch for us. We can list all remote branches with the git branch -r
command. -r
means remote for branch.
到目前为止,我们已经与本地分支机构合作,但是远程分支机构也是分布式软件开发的重要组成部分,因为其他开发人员将推动他们的分支机构,这对我们来说将是远程分支机构。 我们可以使用git branch -r
命令列出所有远程分支。 -r
表示远程分支。
$ git branch -r

列出所有分支(本地和远程)(List All Branches (Local and Remote))
We can also list all branches those resides on local or remote. We will use -a
option to the git branch
command. First the local branches will be listed and then the remote branches will be listed.
我们还可以列出位于本地或远程的所有分支。 我们将在git branch
命令中使用-a
选项。 首先将列出本地分支机构,然后将列出远程分支机构。
$ git branch -a

列出匹配的分支 (List Matched Branches)
We can also list branches with given name pattern. We will use --list
option and provide the string we want to match. In this example we will list only branches those names starts with test
. We will also use wildcard *
for match any character after test
string.
我们还可以列出具有给定名称模式的分支。 我们将使用--list
选项并提供我们要匹配的字符串。 在此示例中,我们将仅列出那些以test
开头的名称的分支。 我们还将使用通配符*
匹配test
字符串后的任何字符。
$ git branch --list 'test*'

更改/切换当前分支(Change/Switch Current Branch)
We generally list local or remote branches in order to change current working or default branch. We can change to the local or remote branch by providing the branch name. In this example we will change to the branch named ismail
.
我们通常列出本地或远程分支以更改当前的工作分支或默认分支。 我们可以通过提供分支名称来更改为本地或远程分支。 在此示例中,我们将更改为名为ismail
的分支。
$ git checkout ismail

翻译自: https://www.poftut.com/how-to-list-local-and-remote-git-branches/
git本地分支和远程分支