克隆分支而不合并主分支

发布于 2024-12-25 23:23:26 字数 375 浏览 0 评论 0原文

有时我希望能够从存储库中提取(通过克隆)。但是当我这样做,然后更改为本地分支以拉入远程分支时,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过去的过去 2025-01-01 23:23:26

每个分支都需要指向某个提交。如果您不指定任何内容,gitbranch 会将新分支指向与 HEAD 相同的提交。

你希望分支指向origin/experiment

git clone http://somewhere.com/something.git
cd something
git branch experiment origin/experiment
git checkout experiment

或者…

git clone http://somewhere.com/something.git
cd something
git checkout -b experiment origin/experiment

或者,因为 git 足够聪明,知道你在这种情况下想要做什么…

git clone http://somewhere.com/something.git
cd something
git checkout experiment

所有这些都会做同样的事情(创建指向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:

git clone http://somewhere.com/something.git
cd something
git branch experiment origin/experiment
git checkout experiment

or…

git clone http://somewhere.com/something.git
cd something
git checkout -b experiment origin/experiment

or, since git is smart enough to know what you’re trying to do in this case…

git clone http://somewhere.com/something.git
cd something
git checkout experiment

All of these will do the same thing (create the new branch pointing at origin/experiment). They’ll also set the branch up to track origin/experiment, so push and pull will be to and from that remote branch.

黎夕旧梦 2025-01-01 23:23:26

如果您只想从远程获取分支而不合并任何内容,您可以执行以下操作,

git fetch --all

或者

git fetch [remote]

我通常只需打开 git gui 并单击远程>获取>[远程],然后我用它

gitk --all 

来查看远程上做了什么分支机构。
如果我愿意的话,我可以合并...
git pull 意味着获取+合并

If you only want to get the branches from the remote or remotes without merging anything you can just do a

git fetch --all

or

git fetch [remote]

I usually just open the git gui and click remotes>fetch>[remote] and then I use

gitk --all 

to see what is done on the remote branches.
I can then merge if I want to...
git pull means a fetch+merge

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文