乐闻世界logo
搜索文章和话题

How do I fetch all Git branches?

1个答案

1

To retrieve all branches in a Git repository, you can use the following Git command:

bash
git branch --all

This command lists all local branches and tracked remote branches (typically displayed as remotes/origin/<branch_name>). If you only want to view remote branches, you can use:

bash
git branch --remote

or the shorthand:

bash
git branch -r

These commands display all branches in the remote repository.

For example, if you are working on a new feature called feature-x, you might create a new branch and push it to the remote repository as follows:

bash
git checkout -b feature-x git push -u origin feature-x

After executing git branch --all, feature-x will appear in both the local branch list and the remote branch list.

Similarly, to check for recent branch changes in the remote repository, you would execute:

bash
git fetch git branch --all

This ensures that the list of remote branches you see is up-to-date. This is particularly useful in collaborative team environments, as it allows you to track new branches added by other team members or branches that have been deleted.

2024年6月29日 12:07 回复

你的答案