Optimuus Prime
Optimuus Prime

Reputation: 61

How to fork and a Git repo to my repo

I have started using Git today and loving it.

I have this doubt - could any one please help me out

A repo for eg https://github.com/octocat/Spoon-Knife can be forked by pressing fork on the page. This then appears in my github like this - https://github.com/usrname/Spoon-Knife.git

I have a test git like this https://github.com/usrname/test.git

And I want the Spoon-Knife to appear within 'test' repo like this https://github.com/usrname/test/Spoon-Knife

How to do this - please let me know.

Upvotes: 1

Views: 104

Answers (1)

VonC
VonC

Reputation: 1329032

You can, but then your https://github.com/usrname/test.git won't be a fork.
Just a regular cloned repo, without any special relationship with the original repo https://github.com/octocat/Spoon-Knife.

  • git clone your fork
  • make a local branch for any remote branch you have fetch with that clone: see the details in "Track all remote git branches as local branches"
  • add test.git as a remote to your local clone, named 'test'
  • push everything back to test.git

That would be:

git clone https://github.com/usrname/Spoon-Knife.git
cd Spoon-Knife
git fetch --tags
remote=origin ; for brname in `git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^\/]+\//,"",$1); print $1}'`; do git branch --set-upstream-to $brname  $remote/$brname ; done
git remote add test https://github.com/usrname/test.git
git config push.default matching
git push --all
git push --tags
git config push.default simple

For the push policies (the config push.default part), see "What is the result of git push origin?".

Upvotes: 1

Related Questions