58

在 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 上创建一个远程分支,然后将它们拉到我的本地仓库?

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

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

请参阅Git -对于类似的问题,为大型项目推送远程分支确实很慢。

4

3 回答 3

104

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

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

创建分支 github ui

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

于 2013-11-13T03:30:53.317 回答
48

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

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

于 2013-11-13T09:24:58.283 回答
2

在创建新分支之前,最好的做法是在本地机器上安装最新的 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)

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

于 2017-07-24T13:11:03.373 回答