从 GitHub 克隆 Git 后,我看不到我的分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3999541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
After Git clone from GitHub, I do not see my branch
提问by Anton
I have a repository on GitHub. It contains master
and one branch.
我在 GitHub 上有一个存储库。它包含master
一个分支。
When I clone it, I obtain only master
and do not see my branch.
当我克隆它时,我只获得master
而看不到我的分支。
Why is it so? How can I see all branches in the repository?
为什么会这样?如何查看存储库中的所有分支?
回答by Cascabel
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.
默认情况下,git clone
只创建一个分支:当前检出的一个,一般是 master。但是,它确实为远程中的所有其他分支创建了远程跟踪分支。将这些视为远程分支的本地副本,可以通过获取更新。它们不是真正的本地分支,因为它们仅用作指向远程分支所在位置的指针,而不是供您处理。
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
).
如果您运行,git branch -a
您将看到所有分支,本地和远程。如果您只想查看远程的,请使用git branch -r
. 如果您更喜欢视觉历史显示,请尝试gitk --all
(或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.
这将使用远程分支作为起点创建一个新的本地分支。
回答by Arun Reddy
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.
这会自动创建一个本地分支,用于跟踪具有相同名称的远程分支。如果您想在 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.
注意:当您克隆时,远程名称默认为“origin”,这与您正在开发的其他机器中使用的远程名称不同。因此,您可以在克隆或推送到原点之前首先命名您的遥控器。
回答by Gonzalo
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.
然后做你的工作,然后推送到远程分支。