简体   繁体   English

如何分叉我自己的GitHub存储库?

[英]How can I fork my own GitHub repository?

So, total newbie to Git. 所以,Git的新手总数。 Been reading through the guides and think I have the basics but am having difficulties accomplishing this one goal. 一直在阅读指南,并认为我有基本但我很难实现这一目标。

I have a repo created for my generic markup source code. 我为我的通用标记源代码创建了一个repo。 Just stuff I reuse for every breakout. 只是我为每次突破重用的东西。 It's called markupDNA.git 它叫做markupDNA.git

I would like to have different directories in my mac sites dir ~/Sites/project-N . 我想在我的mac站点dir ~/Sites/project-N有不同的目录。 Where I build upon the generic stuff and do a breakout of a site. 我建立在通用的东西上并在网站上突破的地方。 I would like these to be tied to my main git repo as forks, but you cannot fork your own repo? 我希望这些与我的主要git repo绑在一起,但是你不能分叉你自己的回购?

I wish I could do something like this: 我希望我能做到这样的事情:

git clone <url> name
git add .
# make changes
git commit -m 'whatever'
git push

But I don't want it to push to origin. 但我不希望它推向原点。 I want it to push to a fork of the markupDNA repo whence it was cloned. 我想让它推到克隆的markupDNA repo的一个分支。 But it seems like it just pushes my changes right up into the origin master. 但它似乎只是将我的更改推送到原始主人。 The idea is to keep the markupDNA clean and just have a lot of forks for my different projects, each of which will have their own cloned dir on my hard drive. 我的想法是保持markupDNA干净,并为我的不同项目提供大量的分支,每个项目都将在我的硬盘上有自己的克隆目录。

Any ideas? 有任何想法吗?

You're doing the right thing. 你正在做正确的事。

cd ~/Sites/
git clone ~/Dev/markupDNA/ project-N
cd project-N
git remote rename origin markupDNA
  • Nav to the folder where you store your projects 导航到存储项目的文件夹
  • clone your base markupDNA repo with custom name 使用自定义名称克隆您的基本markupDNA repo
  • rename the remote so that if you want to an 'origin' later, you can 重命名遥控器,以便在以后想要“原点”时,可以

It will probably be a lot easier to use branches , rather than using separate forks. 使用分支可能要容易得多,而不是使用单独的分支。 You can still have separate checkouts for each branch; 您仍然可以为每个分支机构单独签出; just clone your repo multiple times, and use git checkout in each one to switch it to the appropriate branch (or git checkout -b to create the branch and check it out all at once). 只需多次克隆你的repo,并在每一个中使用git checkout将它切换到适当的分支(或者git checkout -b来创建分支并立即检查它)。 Once you have created the branches, you can push them to GitHub using git push origin <branchname> . 创建分支后,可以使用git push origin <branchname>将它们推送到GitHub。

Surprised no-one has referenced this guy's blog post yet. 惊讶没有人引用这个人的博客帖子

Here's the relevant steps: 以下是相关步骤:

$ git clone git@github.com:YOURNAME/foo.git bar
$ cd bar
$ vim .git/config
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com:YOURNAME/bar.git #replace foo with bar
$ git remote add upstream git@github.com:YOURNAME/foo.git
$ git push -u origin master

Instead of editing the config, I usually use a combination of git remote remove and git remote add . 我通常使用git remote removegit remote add的组合而不是编辑配置。

You could also use git remote rename followed by git remote add if you wanted to keep the upstream origin around. 如果你想保持上游起源,你也可以使用git remote rename然后使用git remote add

This tutorial gives a simple and straightforward answer : 本教程提供了一个简单明了的答案:

  1. Create a new empty github forkedrepo repository 创建一个新的空github forkedrepo存储库
  2. Clone it locally: 在本地克隆:

     git clone https://github.com/YOURUSERNAME/forkedrepo.git 
  3. Add the original github repository as remote of the new local repository: 将原始github存储库添加为新本地存储库的远程:

     git remote add upstream https://github.com/YOURUSERNAME/originalrepo.git 
  4. Pull down a copy of the original github repository to your new local repository: 将原始github存储库的副本下载到新的本地存储库:

     git pull upstream master 
  5. Push the files from your new local repository to new github repository: 将文件从新的本地存储库推送到新的github存储库:

     git push origin master 

This won't be recognized by github as a fork of the original repository, off course, but this is as good as it gets. 当然,这不会被github识别为原始存储库的一个分支,但这样做会很好。

to make true GitHub fork of own repository you can use this steps: 要创建自己的存储库的真正GitHub fork,您可以使用以下步骤:

  1. Create an organization 创建一个组织
  2. Fork to organization 分到组织
  3. Rename forked project 重命名分叉项目
  4. Move back to your account 回到您的帐户

Sure you can clone from a clone. 当然你可以从克隆克隆。 In git there is no concept of a main repo. 在git中没有主要回购的概念。 People often designate a main repo, but that is by convention, not because of a technical reason. 人们经常指定一个主要的回购,但这是按照惯例,而不是出于技术原因。

So you can do everything exactly as you describe and even more. 因此,您可以完全按照您的描述完成所有操作,甚至更多。

For example it makes sense to keep a branch in your breakout sites with ideas for additions or modifications to your generic stuff. 例如,在您的突破网站中保留一个分支是有意义的,可以添加或修改您的通用内容。 You can pull these up towards your generic repo and distribute again from there. 您可以将它们提升到您的通用仓库并从那里再次分发。

You can also use Github's import tool . 您也可以使用Github的导入工具

(it's made for importing from SVN, etc. but you can use it for this too) (它是从SVN等导入的,但你也可以用它)

  • Create new repository in Github. 在Github中创建新的存储库。 IMPORTANT : don't "initialize with a README" 重要提示 :不要“使用自述文件进行初始化”
  • On the next screen click "Import code" 在下一个屏幕上单击“导入代码”
  • Paste the URL to the Github repo you want to import. 将URL粘贴到要导入的Github存储库。 ( screenshot ) 截图

Again, this is creating a new repository and not a true fork on Github. 同样,这是在Github上创建一个新的存储库而不是真正的fork。 But all your branches, history, etc will be there. 但你所有的分支,历史等都将存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM