克隆分支而不合并主分支
有时我希望能够从存储库中提取(通过克隆)。但是当我这样做,然后更改为本地分支以拉入远程分支时,git 假设我想要获取主分支并集成它。我该如何避免这种情况?我确信我可以通过一系列不同的操作/命令来实现我想要的。
我想说,当我想在辅助计算机上的特定分支上工作时,我通常会遇到这种情况。
更新:
我在辅助机器上运行以下命令,我只想在实验分支上工作
git clone http://somewhere.com/something.git
git branch experiment
git checkout experiment
git pull origin experiement
Sometimes I want to be able to pull from a repo (via clone). But when I do that and then change to a local branch to pull-in a remote branch, git assumes I want to take the main branch and integrate it. How do I avoid this? I'm sure I can achieve what I want by a different series of actions/commands.
I'd say I normally run into this when I want to work on a specific branch on a secondary machine.
update:
I run the following commands on a secondary machine where I only want to work on the experiment branch
git clone http://somewhere.com/something.git
git branch experiment
git checkout experiment
git pull origin experiement
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个分支都需要指向某个提交。如果您不指定任何内容,
gitbranch
会将新分支指向与 HEAD 相同的提交。你希望分支指向
origin/experiment
:或者…
或者,因为 git 足够聪明,知道你在这种情况下想要做什么…
所有这些都会做同样的事情(创建指向
origin/experiment
的新分支)。他们还将分支设置为跟踪起源/实验
,因此推送和拉取将在该远程分支之间进行。Each branch needs to point at some commit. If you don’t specify anything,
git branch
points the new branch at at the same commit as HEAD.You want the branch to point at
origin/experiment
instead:or…
or, since git is smart enough to know what you’re trying to do in this case…
All of these will do the same thing (create the new branch pointing at
origin/experiment
). They’ll also set the branch up to trackorigin/experiment
, so push and pull will be to and from that remote branch.如果您只想从远程获取分支而不合并任何内容,您可以执行以下操作,
或者
我通常只需打开 git gui 并单击远程>获取>[远程],然后我用它
来查看远程上做了什么分支机构。
如果我愿意的话,我可以合并...
git pull 意味着获取+合并
If you only want to get the branches from the remote or remotes without merging anything you can just do a
or
I usually just open the git gui and click remotes>fetch>[remote] and then I use
to see what is done on the remote branches.
I can then merge if I want to...
git pull means a fetch+merge