List all remote branches in Git
Git is specifically known as a distributed version control system, there is no central server where we push the code. Nevertheless, we push and pull the required changes in other repositories that we need in branches directly. It gives us the opportunity to branch from the original code base at any time. It allows us to collaborate with other developers more easily and provides a lot of flexibility in our workflow in a team.
You can have multiple local repositories on different machines and push them to the same remote repository when the work is completed. This allows us to clone a repository on one machine to our second machine and start working from there.
Remote tracking branches are local branches that track remote branches. They are local pointers to our remote repository and can be easily used to quickly switch to remote branches. The command git remote
can be used to create them (they are --track
created with the -p option), and they can be used like any other local branch. It is usually created using the following command.
git branch --track <remote-branch> <local-branch>
--track
Options can be added git branch
to the command, and we can also use it to track branch commits, as follows:
git branch --track <remote-branch> <local-branch>.
List Git remote branches
In this section, we will discuss how to list all remote branches in Git. We can list the remote branches associated with multiple commands listed below. There are various commands in Git that can display different types of branches depending on your current situation in the repository.
We will use git branch
the command to view local branches. git branch -a
The command lists the local branches and remote tracking branches that we have set up to keep in sync with the remote branches. git branch -r
The command lists the remote tracking branches but not the local branches. git remote show
The command can also list remote branches. The syntax for list branches in Git is as follows.
git branch -a
git branch -r 命令
The syntax is as follows.
git branch -r
git remote show
The command syntax is,
git remote show [name]
Where name
is the name of the remote branch in the repository. To view the remote branch connected to the master branch in our remote origin repository, use the following command:
git branch -r origin/master
We will use the following command to view the remote tracking branch connected to the master branch in the remote origin repository.
git branch -a origin/master
We can say, to see remote branches that are not tracked by your local repository, add -a
the flag.
git remote show origin -a * remote origin
If we have a lot of remote branches, we may find it useful to limit the output to only the tracked remote branches using the following command.
git remote show origin --tracked * remote origin
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Changing drives in Git Bash
Publish Date:2025/03/30 Views:56 Category:Git
-
This short article will discuss how we can use Git Bash to have a Unix-style command line environment in Windows operating system and run multiple commands in this terminal. Git Bash Git is a collection of command-line utilities created to
Adding a remote branch in Git
Publish Date:2025/03/30 Views:142 Category:Git
-
Git does not allow its developers to create new branches on remote repositories. But instead, we can push an already existing local branch, and after doing so, we can bring it to the remote repository using some Git commands. In every versi
Synchronize your local repository with a remote repository in Git
Publish Date:2025/03/30 Views:92 Category:Git
-
This article outlines the process of syncing your local repository with a remote repository. We will also see how to sync a GitHub branch with a remote repository on the command line. Synchronize your local repository with a remote reposito
Creating a remote repository from a local repository in Git
Publish Date:2025/03/30 Views:105 Category:Git
-
This article discusses the necessary steps to create a remote repository based on a local repository. This is ideal when you have a local repository that needs to be available on a remote or SSH-enabled server. Creating a remote repository
Removing the upstream repository in Git
Publish Date:2025/03/30 Views:177 Category:Git
-
This article will teach you how to delete an upstream repository in Git. We may sometimes need to delete or change the remote repository that we use with our local repository. To do this, we can use the Git command git remote . Removing the
Git remote add SSH
Publish Date:2025/03/30 Views:53 Category:Git
-
In this day and age, the most widely used version control system is Git, which is operated by most developers within a team structure. This is mainly used to increase code efficiency, no matter how big or critical the project is. In this se
Differences between Git Reset, Revert and Checkout commands
Publish Date:2025/03/30 Views:185 Category:Git
-
This article discusses the differences between the git reset , , git revert and git checkout commands. These are some of the most useful Git utilities that allow us to undo certain changes in our repository. It’s easy to get confused with
Git revert local commits
Publish Date:2025/03/30 Views:84 Category:Git
-
When a software engineer or a web developer uses Git, it is obvious that he pushes a lot of code and commits to the Git repository every day, and while doing so, the need to undo or revert a particular commit or a set of commits arises from
Deleting local and remote Git branches
Publish Date:2025/03/30 Views:146 Category:Git
-
Git comes into play in version control systems when you are working with a team and the entire team is making changes to the same code repository. Creating a new branch in Git is relatively easy than other version control systems and deleti