Git: List Remote Branches: A Step-By-Step Guide | Career Karma
Maybe your like
You can list the remote branches associated with a repository using the git branch -r, the git branch -a command or the git remote show command. To see local branches, use the git branch command.
The git branch command lets you see a list of all the branches stored in your local version of a repository. To see the remote branches associated with your repository, you need to append the -r flag to the end of the git branch command.
Find your bootcamp match Select Your Interest Software Engineering Design Data Science Data Analytics Digital Marketing Cyber Security Sales Your experience Beginner Intermediate Advanced Time to start Now 1 Months 3 Months 6 Months+ GET MATCHED By completing and submitting this form, you agree that Career Karma Platform, LLC may deliver or cause to be delivered information, advertisements, and telemarketing messages regarding their services by email, call, text, recording, and message using a telephone system, dialer, automated technology or system, artificial or prerecorded voice or message device to your email and/or telephone number(s) (and not any other person’s email or telephone number) that you entered. Consent is not a condition of receiving information, receiving Career Karma services, or using the website, and you may obtain information by emailing [email protected]. Message & Data rates may apply. Message frequency may vary. Text STOP to unsubscribe. Terms of Service and Privacy Policy govern the processing and handling of your data. XFind your bootcamp match
First Name Last Name Your e-mail Your phone number GET MATCHED By completing and submitting this form, you agree that Career Karma Platform, LLC may deliver or cause to be delivered information, advertisements, and telemarketing messages regarding their services by email, call, text, recording, and message using a telephone system, dialer, automated technology or system, artificial or prerecorded voice or message device to your email and/or telephone number(s) (and not any other person’s email or telephone number) that you entered. Consent is not a condition of receiving information, receiving Career Karma services, or using the website, and you may obtain information by emailing [email protected]. Message & Data rates may apply. Message frequency may vary. Text STOP to unsubscribe. Terms of Service and Privacy Policy govern the processing and handling of your data.In this guide, we discuss how to use the git branch -r command to show remote branches. We also discuss how to use the git remote show command to show branches on the remote version of your repo.
Git: List Remote Branches
There are three ways to list the remote branches associated with a Git repository:
- git branch -a: See both local and remote branches
- git branch -r: See only remote branches
- git remote show: See remote branches and associated metadata
The most common commands are git branch -a and git branch -r because they only list the branches. git remote show provides more detailed information about each branch which is not always necessary.
Git: List All Remote Branches Using git branch
We have a Git repository called ck-git. We’re unsure whether the branch we want to create, dev2.2-fix, exists in our repository.
The git branch -r Flag
To check for this branch, we can use the git branch command:
git branchThis command returns a list of all the local repository branches:
* master devThe asterisk (*) denotes the branch we are currently viewing. We can see that the branch that we want to create (“dev2.2-fix”) does not exist.
Before we create the branch, we want to check if the branch exists on our remote. We can do this by adding the -r flag to the git branch command:
git branch -rThis command retrieves the branches on the remote version of our repository:
origin/HEAD -> origin/master origin/dev2.2-fix origin/masterWe can see that our remote repository has a branch called dev2.2-fix already. We now know that the branch exists on our remote repository but not our local one.
This means we need to fetch an existing branch to our local machine, so we can get to work on writing our code. We don’t need to create a new branch.
We can fetch the existing branch from our remote repository using the Git fetch command:
git fetch origin dev2.2-fixThis will let us retrieve the dev2.2-fix branch from our origin repository. “origin” is the name of the main remote repo to which we push our code. We can see that once we run this command a new branch is created:
From https://github.com/career-karma-tutorials/ck-git * branch dev2.2-fix -> FETCH_HEADThe git branch -a Flag
The -a flag associated with the git branch command returns all the local and remote branches associated with a repository.
Consider the following command:
git branch -aOur command returns:
* master remotes/origin/activity-feed remotes/origin/masterWe can see that there are branches that did not appear when we run git branch -r. This is because git branch -r only returns remote branches. git branch -a returns remote tracking branches and local branches.
Remote branches are denoted by the “remotes” label.
Git: List All Remote Branches Using git remote show
The git remote show displays detailed information about the branches associated with a remote repository. This command takes one argument: the name of the remote whose branches you want to view.
The git branch -r command is sufficient if you want a brief overview of all the branches stored on a remote. If you want more detailed information, the git remote show command may be more useful. This command returns:
- All remote branches
- The local branches configured with the git pull command
- The branches configured with the git push command
Let’s run the git remote show command on our “origin” remote, which is the name of the main remote associated with our project. We can expect to see the origin 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 the branches on our remote repository using the git remote show command:
git remote show originThis command displays all the remotes associated with “origin”. This is the main remote attached to our repo. Let’s take a look at what the command displays:
* remote origin Fetch URL: https://github.com/career-karma-tutorials/ck-git Push URL: https://github.com/career-karma-tutorials/ck-git HEAD branch: master Remote branches: dev2.2-fix tracked master tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (local out of date)We can see that there are two branches on our remote repository that we are tracking. These branches are called master and dev2.2-fix.
"Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!"
Venus, Software Engineer at Rockbot
Find Your Bootcamp MatchWe have not configured a pull or push operation with our dev2.2-fix branch. This is because we haven’t pulled code from or pushed code to that branch yet.
Conclusion
The git remote -r command lets you see a list of all the branches on a particular remote. If you need more information about the remotes associated with a repository, you can use the git remote show command.
Now you have the knowledge you need to use Git list branches on remote commands. To learn more about working with Git, read our How to Learn Git guide.
Tag » All Git Branches
-
Git Branches: List, Create, Switch To, Merge, Push, & Delete
-
Git List Branches – How To Show All Remote And Local Branch Names
-
3 Ways To List Branches In Git (Local And Remote) - JQuery-AZ
-
Git-branch Documentation - Git
-
Branches In A Nutshell - Git
-
Git-show-branch Documentation - Git
-
Remote Branches - Git
-
How Do I Fetch All Git Branches? - Stack Overflow
-
Git Branch | Atlassian Git Tutorial
-
How To Delete All Git Branches Except Master Or Main Exampleb
-
Git Fetch | Atlassian Git Tutorial
-
Manage Git Branches | IntelliJ IDEA - JetBrains
-
How To Delete All Local Git Branches | By Riccardo Giorato - Medium