Chat Zalo Chat Messenger Phone Number Đăng nhập
Git: List Remote Branches: A Step-By-Step Guide | Career Karma

Git: List Remote Branches: A Step-By-Step Guide | Career Karma

You can list the remote branches associated with a repository by using the git branch -r, git branch -a, or git remote show command. To view local branches, use the git branch command.

The git branch command allows you to view a list of all branches stored in your local version of a repository. To view the remote branches associated with your repository, you must add the -r flag to the end of the git branch command.

In this guide, we discuss how to use the git branch -r command to display remote branches. We also discussed how to use the git remote show command to display branches in the remote version of your repository.

Git: List of remote branches

There are three ways to list

the remote branches associated with a Git repository: Git branch -a: View local and remote branches git branch -r: View remote branches only git remote

  • show: View remote branches and associated metadata
  • The most common commands are git branch –

  • a and
  • git

branch -r because they only list branches. Git Remote Show provides more detailed information about each branch which is not always necessary.

Git: List of all remote branches Using the

git branch

We have a Git repository called ck-git. We are not sure if the branch we want to create, dev2.2-fix, exists in our repository.

The git

-r Flag

branch

To check this branch, we can use the git

branch command:

This command returns a list of all branches in the local repository:

The asterisk (*) indicates the branch we are currently viewing. We can see that the branch we want to create (“dev2.2-fix”) does not exist.

Before creating the branch, we want to check if the branch exists on our remote control. We can do this by adding the -r flag to the git

branch command:

This command retrieves the branches in the remote version of

our repository:

We can see that our remote repository already has a branch called dev2.2-fix. We now know that the branch office exists in our remote repository, but not in the local one.

This means that we need to get an existing branch to our local machine, so we can get to work writing our code. We don’t need to create a new branch.

We can get the existing branch from our

remote repository using the Git fetch command:

This will allow us to retrieve the dev2.2-fix branch from our source repository. “Origin” is the name of the master remote repository to which we send our code. We can see that once we execute this command a new branch is created

: The git

a Flag branch

The -a flag associated with the git branch command returns all the local and remote branches associated with a repository

.

Consider the following command

:

Our command returns:

We can see that there are branches that did not appear when we run git branch -r. This is because the git -r branch only returns remote branches. Git branch: a returns remote tracking branches and local branches.

Remote branches

are labeled “remote.”

Git: List all

remote branches using git remote show

The remote presentation of git displays detailed information about the branches associated with a remote repository. This command takes an argument: the name of the remote control whose branches you want to view.

The git branch -r command is sufficient if you want a brief description of all branches stored in a remote control. If you want more detailed information, the git remote show command may be more useful. This command returns:

All remote branches Local branches configured with the git

    pull command

  • Branches configured
  • with the git push command Let’s run the

  • git

remote show command on our “

origin” remote control, which is the name of the main remote control associated with our project. We can expect to see the source master branch, the main branch on our remote, and any other branches we have.

For most users, this command will provide more information than they need. But, it exists if you ever need to use it.

Let’s retrieve a list of all branches in our remote repository using the git remote show command:

This command displays all remote controls associated with “origin”. This is the main remote control connected to our repository. Let’s take a look at what the command shows:

We can see that there are two branches in our remote repository that we are crawling. These branches are called master and dev2.2-fix.

We have not configured a pull or push operation with our dev2.2-fix branch. This is because we have not yet extracted code or submitted code to that branch.

Conclusion

The git remote -r command allows you to view a list of all branches on a particular remote. If you need more information about the remote controls associated with a repository, you can use the git remote show command.

You now have the knowledge you need to use Git list branches in remote commands. To learn more about working with Git, read our How to learn Git guide.

Contact US