【问题标题】:Create a remote branch on GitHub在 GitHub 上创建远程分支
【发布时间】:2013-11-25 12:10:09
【问题描述】:

在 SVN 中我至少有两种创建分支的方法:

svn cp /home/me/localcheckout/trunk /home/me/localcheckout/branches/newbranch
svn cp http://server/trunk http://server/branches/newbranch

首先在本地创建它,然后我必须提交整个分支。
第二个在服务器上创建它。

第二个的好处是我可以 svn 切换我的本地中继,对一些文件进行一些更改并提交几 KB。

是否可以使用 Git 来实现?
有没有办法在 GitHub 上创建一个远程分支,然后将它们拉到我的本地仓库?

我问的原因是我正在尝试使用我的手机互联网连接从 master 推送几个 KB 到一个新的远程分支,但是当我推送时它想要推送大约 400 MB!

写入对象:22% (54080/245586),86.74 MiB | 13 KB/秒

请参阅Git - pushing a remote branch for a large project is really slow 了解类似问题。

【问题讨论】:

    标签: git github git-branch


    【解决方案1】:

    看起来 github 有一个用于创建分支的简单 UI。我打开了分支下拉菜单,它提示我“查找或创建分支...”。输入新分支的名称,然后点击出现的“创建”按钮。

    要从 github 检索新分支,请使用标准 git fetch 命令。

    不过,我不确定这是否会对您的潜在问题有所帮助,因为无论将其推送到哪个分支,推送到服务器的基础数据(提交对象)都是相同的。

    【讨论】:

    • 这个默认是从master创建一个分支;如果我想从 master 以外的东西分支怎么办?
    • 我刚试过,如果你先在下拉列表中选择其他分支,然后输入你的新分支名称,它将从你选择的分支创建。
    【解决方案2】:

    Git 应该了解服务器上已经存在哪些文件,除非您以某种方式对您的树产生了巨大的影响并且需要发送新的更改。

    使用当前状态的副本创建一个新分支

    git checkout -b new_branch #< create a new local branch with a copy of your code
    git push origin new_branch #< pushes to the server
    

    您能否描述一下您为了解可能导致您的存储库需要向服务器发送这么多数据而执行的步骤。

    【讨论】:

      【解决方案3】:

      在创建新分支之前,最好的做法是在本地机器上安装最新的 repo。请按照以下步骤创建无错误的分支。

       1. $ git branch (check which branches exist and which one is currently active (prefixed with *). This helps you avoid creating duplicate/confusing branch name)
       2. $ git branch <new_branch> (creates new branch)
       3. $ git checkout new_branch
       4. $ git add . (After making changes in the current branch)
       5. $ git commit -m "type commit msg here"
       6. $ git checkout master (switch to master branch so that merging with new_branch can be done)
       7. $ git merge new_branch (starts merging)
       8. $ git push origin master (push to the remote server)
      

      我提到了这个blog,我发现它是一种更清洁的方法。

      【讨论】:

      • 问题询问如何远程而不是本地创建并推送。我已经在问题中说明了为什么我推送它使用大量数据。你有没有读过这个问题和已经存在的答案???
      猜你喜欢
      • 2012-07-01
      • 1970-01-01
      • 2022-12-08
      • 1970-01-01
      • 1970-01-01
      • 2013-02-08
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多