Remote Branches
Remote repositories may also have remote branches. Working with these remote branches is a straightforward process.
Pushing Branches
When working with a remote repository, it is possible to share branches created locally. To share a branch with a remote repository, the git push
command is used, followed by the remote repository, commonly called origin
, and the branch's name.
git push -u origin new-branch
Listing Remote Branches
Running the git branch
command will return a list of local branches. However, to view all branches, including remote branches, the --all
option should be added.
git branch --all
Fetching Branches
The git fetch
command retrieves the branches from a remote repository. If no remote repository is specified, origin
will be used.
git fetch origin