Git is specifically known as a decentralized version control system. When users work as a team on the same project, they use this platform to push the project’s documents or code files to the remote repository. We often need branches to make desired changes, and after that, commit, push and pull these files into the remote repository to update the previous files for everyone.
However, sometimes it is required to figure out how many branches exist on a remote repository, so you can pull and check them out and merge these branches into their local branches.
This study will discuss the method of listing remote branches in Git.
How to List Remote Branches in Git?
There are different Git commands available to check the list of all of the remote branches of the specific repository, such as:
- git branch
- git ls-remote
- git show-branch
Let’s check them out one by one!
First, open up the “Git Bash” on your system with the help of the “Startup” menu:
Next, move to the remote directory which is cloned on your system using the “cd” command:
Method 1: List Remote Branches in Git Using “git branch” Command
To check the list of remote repository branches, execute the “git branch” command with the “-r” flag:
Here, “-r” flag is the equivalent to that “–remotes”. This command will return the list of all remote branches. For instance, our remote Cloning_branch repo has the following branches:
Method 2: List Remote Branches in Git Using “git ls-remote” Command
If you want to get the list of remote branches with the remote hashes, then execute the below-mentioned command:
The “–head” option used to only list the branches name:
Or you can also run the same command without the “–head” option:
Method 3: List Remote Branches in Git Using “git show-branch” Command
The “git show-branch” command with the “-r” option is also utilized for displaying the list of all remote branches that exist in the remote directory:
We have executed different commands for listing remote branches in Git.
Conclusion
There are different commands that are utilized for listing all remote branches, such as “git branch”, which is used to only list the branch names. To list branches with a hash, run the “git ls-remote –heads” command. To display the reference information of the latest Git commit hash of branches, execute the “git ls-remote -r” command, and “git show-branch” is also used for displaying the list of branches. This study demonstrated the method of how to list remote branches in Git.