git 在 GitHub 上创建远程分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19944510/
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
Create a remote branch on GitHub
提问by opticyclic
In SVN I have at least two ways to create a branch:
在 SVN 中,我至少有两种创建分支的方法:
svn cp /home/me/localcheckout/trunk /home/me/localcheckout/branches/newbranch
svn cp http://server/trunk http://server/branches/newbranch
The first creates it locally then I have to commit the whole branch.
The second creates it on the server.
第一个在本地创建它然后我必须提交整个分支。
第二个在服务器上创建它。
The benefit of the second is that I can svn switch my local trunk, make a few changes to some files and commit just a few KB.
第二个的好处是我可以 svn 切换我的本地主干,对一些文件进行一些更改并只提交几 KB。
Is it possible to achieve that using Git?
Is there a way of creating a remote branch on GitHub then pull them to my local repo?
使用 Git 可以实现吗?
有没有办法在 GitHub 上创建远程分支然后将它们拉到我的本地仓库?
The reason that I ask is that I am trying to push a couple of KB to a new remote branch from master using my phones internet connection but when I push it wants to push about 400 MB!
我问的原因是我试图使用我的手机互联网连接将几个 KB 从 master 推送到一个新的远程分支,但是当我推送时,它想要推送大约 400 MB!
Writing objects: 22% (54080/245586), 86.74 MiB | 13 KiB/s
写入对象:22% (54080/245586),86.74 MiB | 13 KB/秒
See Git - pushing a remote branch for a large project is really slowfor a similar question.
请参阅Git -对于类似问题,为大型项目推送远程分支确实很慢。
回答by Matt McHenry
It looks like github has a simple UI for creating branches. I opened the branch drop-down and it prompts me to "Find or create a branch ...". Type the name of your new branch, then click the "create" button that appears.
看起来 github 有一个用于创建分支的简单 UI。我打开了分支下拉菜单,它提示我“查找或创建一个分支......”。输入新分支的名称,然后单击出现的“创建”按钮。
To retrieve your new branch from github, use the standard git fetch
command.
要从 github 检索新分支,请使用标准git fetch
命令。
I'm not sure this will help your underlying problem, though, since the underlying data being pushed to the server (the commit objects) is the same no matter what branch it's being pushed to.
不过,我不确定这是否会帮助您解决潜在问题,因为无论推送到哪个分支,推送到服务器的基础数据(提交对象)都是相同的。
回答by Mohammad AbuShady
Git is supposed to understand what files already exist on the server, unless you somehow made a huge difference to your tree and the new changes need to be sent.
Git 应该了解服务器上已经存在哪些文件,除非您以某种方式对您的树产生了巨大的影响并且需要发送新的更改。
To create a new branch with a copy of your current state
使用当前状态的副本创建新分支
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
Can you please describe the steps you did to understand what might have made your repository need to send that much to the server.
您能否描述一下您为了解可能使您的存储库需要将这么多内容发送到服务器的原因而采取的步骤。
回答by w1n5rx
Before creating a new branch always the best practice is to have the latest of repo in your local machine. Follow these steps for error free branch creation.
在创建新分支之前,最佳做法始终是在本地机器中拥有最新的 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)
I referred this blogand I found it to be a cleaner approach.
我提到了这个博客,我发现它是一种更简洁的方法。