Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

git - How can I clone a GitHub repository, then push it to a new repository as origin?

Let's say you have a framework on GitHub and want to use it to create other sites, so you want to:

  • clone it locally
  • change it
  • push it to a new repository

These are the instructions I currently have for this:

  • git clone https://github.com/yourname/framework.git newsite
  • cd newsite
  • (make changes)
  • on Github, create new repository called "newsite"
  • git remote add origin2 https://github.com/yourname/newsite.git
  • git push -u origin2 master

I unfortunately have to push to origin2 otherwise it pushes back to my original framework, which I don't want, of course.

But this causes the problem that I may inadvertently push to origin at some time in the future.

How can I make my new repository origin?

Or is there a more straight-forward way to do this when you want to (1) clone a repository, but (2) push it to a different repository?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you would want to update both fetch and push URL, pointing to same repo

git remote set-url origin <new-repo-url>

Below command will set new repository as default repo to push only.

git remote set-url --push origin <new-repo-url>

If need to unset the Push URL setup by above command

 git remote set-url --delete --push origin <current-push-URL>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...