![]() These commands are useful when you want to see the remote branches that exist in a remote repository, and they can help you keep track of the changes that are made by other developers. In conclusion, listing remote branches in Git is a simple process that can be achieved by using the git branch -r or git branch -a command. In this output, the asterisk (*) indicates the current branch, and the branches that are prefixed with remotes/origin/ are the remote branches. When you run this command, Git will display a list of all the branches, including the remote branches.įor example, if you have a local branch named “local1” and a remote repository named “origin” that contains three remote branches as defined in above command, you will see the following output: List local + remote branches in Git The -a option stands for -all and it tells Git to list all the branches, both local and remote. You can also use the following command to list all the branches, both local and remote: git branch -a When you run this command, Git will display a list of all the remote branches that exist in the remote repository.įor example, if you have a remote repository named origin and it contains three remote branches named “main”, “staging” and “development”, you will see the following output: List remote branches in Git List Local and Remote (Both) Branches ![]() The -r option stands for -remote and it tells Git to list only the remote branches. To list remote branches in Git, you can use the following command: git branch -r If Git is installed, you will see the version of Git that is installed on your machine. ![]() You can check if Git is installed by running the following command in your terminal: git -version Check Git Clientīefore we begin, it is important to make sure that you have Git installed on your machine. In this article, we will discuss how to list remote branches in Git. Remote branches are useful when you want to collaborate with other developers or when you want to work on a project from a different location. The easiest way is just to use the git branch. See the command and its output:įor listing the remote tracking branches, use the -r or –remotes option with show-branch command.Local branches are branches that exist only on your local machine, whereas remote branches are branches that exist on a remote repository, such as Github, BitBucket, AWS CodeCommit, or Gitlab. The comments have enlightened me quite a bitthere seems to always be more than one way to skin a cat using Git. In this example, I used the show-branch command for seeing branches and commits made. ![]() This is followed by using the command for listing all branches and see the output: In this example, I have used the checkout command for making the br-tst1 branch active. You can see all local branches in above graphic – without active branch green color.Īnd if you want to get only remote branches then remove the -v in above command: The grep command is a big topic, however, in our context of showing branches, the command below shows how you may use it: Using Git grep command for local branches examplesįor searching any committed tree, working directory etc. Only the local branches are listed in white with the master as green (which is the active branch). The output shows only the branches in red that are remote branches.Īgain, by using the branch command without any option lists the local branches only. The command below shows how to list only remote branches for the set repository: The branches in red are the remote branches i.e. The branches in white are the local branches whereas green (master) represents the active branch. The result is shown in the graphic below: So, we have three local and two remote branches apart from the master branch in both repositories.įor listing all branches – in local and remote repositories, run this command on the terminal: This is followed by creating remote branches: The following commands are used for creating the local branches: Learn how to create local/remote repos/branches I will create a few branches in both repositories and then use the commands to list all branches as well as branches in the remote repository only with screenshots.įor our example, I have created a few branches in local as well as remote repositories. In the next section, I will show you an example of a remote and local repository. So, it becomes quite handy to know the way of listing all branches in the repo that helps in switching to appropriate branch as well. Our repositories may contain a number of branches and sometimes it is hard to remember all – whether on the local or remote repo. You may also use the show-branch command for seeing the branches and their commits as follows:Īs working with Git version control system, we have to work with branches. If you require only listing the remote branches from Git Bash then use this command: The command to list all branches in local and remote repositories is:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |