How can I fork my own GitHub repository?

回眸只為那壹抹淺笑 提交于 2019-12-17 07:26:07

问题


So, total newbie to 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. Just stuff I reuse for every breakout. It's called markupDNA.git

I would like to have different directories in my mac sites 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?

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. 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.

Any ideas?


回答1:


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). Once you have created the branches, you can push them to GitHub using git push origin <branchname>.




回答2:


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
  • rename the remote so that if you want to an 'origin' later, you can



回答3:


This tutorial gives a simple and straightforward answer :

  1. Create a new empty github forkedreporepository
  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:

    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:

    git pull upstream master
    
  5. Push the files from your new local repository to new github repository:

    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.




回答4:


to make true GitHub fork of own repository you can use this steps:

  1. Create an organization
  2. Fork to organization
  3. Rename forked project
  4. Move back to your account



回答5:


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.

You could also use git remote rename followed by git remote add if you wanted to keep the upstream origin around.




回答6:


Sure you can clone from a clone. In git there is no concept of a main repo. 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.




回答7:


You can also use Github's import tool.

(it's made for importing from SVN, etc. but you can use it for this too)

  • Create new repository in 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. (screenshot)

Again, this is creating a new repository and not a true fork on Github. But all your branches, history, etc will be there.



来源:https://stackoverflow.com/questions/3772684/how-can-i-fork-my-own-github-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!