Git is specifically known as a distributed version control system with no central server where we push our code. Despite this, we push and pull our desired changes directly to and from other repositories where we want in a branch. It allows us an opportunity to branch out from the original codebase anytime. It enables us to work with other developers more easily and gives us a lot of flexibility in our workflow in a team.
You can have several local repositories on different machines and push them to the same remote repository when the work is finished. This lets us clone the repository on one machine to our second machine and work on it from there as well.
Remote-tracking branches are local branches that track remote branches. They are local pointers to our remote repository, and they can be used easily to switch to a remote branch quickly. The command
git remote can be used to create them (they are created with the
--track option), and they can be used like any other local branch. It is usually created with the following command.
git branch --track <remote-branch> <local-branch>
--track option can be added to the
git branch command using which we can track the branch commits as well, the command is following:
git branch --track <remote-branch> <local-branch>.
List Git Remote Branch
This section will discuss how to list all the remote branches in Git. We can list the remote branches associated with multiple commands listed below. There are various commands in Git that will display different types of branches depending on your current situation in the repository.
We will use the
git branch command to see local branches. The
git branch -a command lists local branches and remote-tracking branches that we have set up to keep in sync with remote branches. The
git branch -r command lists remote-tracking branches but not local branches. The
git remote show command can also list remote branches. The syntax for the list branches in Git is following.
git branch -a
The syntax for the
git branch -r command is below.
git branch -r
git remote show command syntax is,
git remote show [name]
name is the name of a remote branch in a repository. To see remote branches connected with the master branch in our remote origin repository, use the following command:
git branch -r origin/master
We’ll use the below command to see remote-tracking branches connected with the master branch in our remote origin repository.
git branch -a origin/master
We can say, to see remote branches that aren’t tracked by the local repository, add the
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 tracked remote branches using the following command.
git remote show origin --tracked * remote origin
- Git Fork vs Branch
- Difference Between Forking and Branching on GitHub
- View Merged and Unmerged Branches in Git
- Git Show Remote Tracking Branches
- Create an Empty Branch on GitHub
- Move Git Branch Pointer to Different Commit