How To List Git Remote Branches of Repository From Github

We can list of remote branches in git using the fetch command. We need to pull the git remote repository and check list using the command.

Simply, we can list remote branches and you will need to add the credentials if it’s your private repository to add the remote repository.

How To List Git Remote Branches of Repository In Github:

First of all, you have Git installed on your machine. you need to create a folder where you will initialize a git repository and pull the changes from the Github repository.

Check Out: How To Install Git Bash and Access AWS EC2 Instance

Run the below command to pull the changes from the git repository and check the list. we will add the remote repository as well. 

[root@example ~]# cd data/
[root@example data]# git init
Initialized empty Git repository in /root/data/.git/
[root@example data]# git remote add origin https://github.com/Aryango/Technical.git
[root@example data]# git pull https://github.com/Aryango/Technical.git
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 51 (delta 4), reused 2 (delta 2), pack-reused 41
Unpacking objects: 100% (51/51), done.
From https://github.com/Aryango/Technical
* branch HEAD -> FETCH_HEAD
[root@example data]# ls
aa abc bb chat ff gotcha hello lopa smartgit testwithabc valid

As you can see first we have added the remote repository then pull the changes in the folder.

Method 1:

Check Git Remote Branches:

You can run the below command to check the remote branches in this repository. The refs’ path is /root/data/.git/refs

[root@example refs]# git ls-remote 
From https://github.com/Aryango/Technical.git
4a7161abe9b95bb63cf5f5e181eb45f25e18f05c            HEAD
8a4e29db579499125ef20b1bdd3513d88a746fde            refs/heads/dev
843c08587bf331bad95bab3800c517d2c5e0e919            refs/heads/failure
4a7161abe9b95bb63cf5f5e181eb45f25e18f05c            refs/heads/master

Check Out: How To Install Git (Distributed Version Control) In Ubuntu 19.04

We can also find the remote branches using the below command. The format is: 

git ls-remote --heads <remote-name>
[root@example data]# git ls-remote --heads https://github.com/Aryango/Technical.git
8a4e29db579499125ef20b1bdd3513d88a746fde      refs/heads/dev
843c08587bf331bad95bab3800c517d2c5e0e919      refs/heads/failure
4a7161abe9b95bb63cf5f5e181eb45f25e18f05c      refs/heads/master

Method 2:

Check Git Remote Branches Using Fetch:

We can also use the fetch command in the git that will help you track the remote branches. Simply run the fetch command from this location /root/data/.git/refs/heads

check list remote repository

Without running the fetch command, you won’t see the most current branches.

Check Out: How To Install Windows Server 2016 On Vmware Workstation

Now we have fetched the remote-tracking branches and we need to check the branches using the below command. 

git branch -a

git fetch

Once you have run the fetch command, you can also use git branch -r command.

If you want to update all the remotes, use the below command.

[root@example heads]# git remote update --prune
Fetching origin

We can also check the remote repository added using the below commands.

[root@example heads]# git remote -v
origin https://github.com/Aryango/Technical.git (fetch)
origin https://github.com/Aryango/Technical.git (push)

That’s it.

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment