在从 GitHub 克隆 Git 之后,我没有看到我的分支

我在 GitHub 上有一个仓库,它包含 master和一个分支。

当我克隆它时,我只获得 master,并且看不到我的分支。

为什么会这样? 我怎样才能看到存储库中的所有分支?

66104 次浏览

Use:

git branch -r

This will show you all remote branches. You can then do:

git branch -t my_local_branch origin/remote_branch
git checkout my_local_branch

Then do your work and then push to the remote branch.

By default, git clone creates only one branch: the currently checked out one, generally master. However, it does create remote tracking branches for all other branches in the remote. Think of these as local copies of the remote's branches, which can be updated by fetching. They're not real local branches, as they're intended only as pointers to where the remote's branches are, not for you to work on.

If you run git branch -a you'll see all branches, local and remote. If you want to see just the remote ones, use git branch -r. If you prefer a visual history display, try gitk --all (or gitk --remotes).

To create a local branch to work on, use

git branch <branch-name> origin/<branch-name>

That'll create a new local branch using the remote's branch as the starting point.

You can directly do:

git checkout <original-remote-branch-name>

This automatically creates a local branch which tracks the remote branch with the same name. Do this always after cloning, if you want to work on a particular branch other than master.

Note: When you clone the remote name is by default 'origin' which is different from the remote name used in other machines where you are developing. So, you can initially name your remote before cloning or push to origin ever after.