Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning a repo from someone else's Github and pushing it to a repo on my Github

Tags:

git

github

I cloned the repo at https://github.com/railstutorial/sample_app_rails_4 and made a lot of changes to it (I used it as a starting point for my own app), and now I would like to push the changed app to a repo on my own github account.

How can I change what github repo it is linked to?

like image 803
jackerman09 Avatar asked Aug 13 '13 03:08

jackerman09


People also ask

Can I clone someone else's GitHub repository?

You can clone or fork a repository with GitHub Desktop to create a local repository on your computer. You can create a local copy of any repository on GitHub that you have access to by cloning the repository. If you own a repository or have write permissions, you can sync between the local and remote locations.

How do I copy a repository from another repository to my GitHub account?

Navigate to the repository you just cloned. Pull in the repository's Git Large File Storage objects. Mirror-push to the new repository. Push the repository's Git Large File Storage objects to your mirror.

Can I clone a repo with a different name?

The fastest way to change the folder name when cloning a GitHub repository is to simply specify the name you want at the end of the git clone command. Here's a short video showing the entire process: When you're done downloading the repo do cd your-app-name to enter your directory with all the Create React App files.


2 Answers

As Deefour says, your situation isn't much unlike the one in Change the URI (URL) for a remote Git repository. When you clone a repository, it is added as a remote of yours, under the name origin. What you need to do now (as you're not using the old source anymore) is change origin's URL:

$ git remote set-url origin http://github.com/YOU/YOUR_REPO

If the original repository would update often and you want to get those updates from time to time, then instead of editing origin it would be best to add a new remote:

$ git remote add personal http://github.com/YOU/YOUR_REPO

Or maybe even call the old one upstream:

$ git remote rename origin upstream
$ git remote add origin http://github.com/YOU/YOUR_REPO

Then, whenever you want to get changes from upstream, you can do:

$ git fetch upstream

As this the source is a sample repository (seems to be kind of a template to start off), I don't think there's a need to keep it nor fork it at all - I'll go with the first alternative here.

like image 184
mgarciaisaia Avatar answered Oct 08 '22 19:10

mgarciaisaia


GitHub: git clone someone else's repository & git push to your own repository

I'm going to refer to someone else's repository as the other repository.


  1. Create a new repository at github.com. (this is your repository)

    • Give it the same name as the other repository.
    • Don't initialize it with a README, .gitignore, or license.
  2. Clone the other repository to your local machine. (if you haven't done so already)

    • git clone https://github.com/other-account/other-repository.git
  3. Rename the local repository's current 'origin' to 'upstream'.

    • git remote rename origin upstream
  4. Give the local repository an 'origin' that points to your repository.

    • git remote add origin https://github.com/your-account/your-repository.git
  5. Push the local repository to your repository on github.

    • git push origin master

Now 'origin' points to your repository & 'upstream' points to the other repository.

  • Create a new branch for your changes with git checkout -b my-feature-branch.
  • You can git commit as usual to your repository.
  • Use git pull upstream master to pull changes from the other repository to your master branch.
like image 98
Derek Soike Avatar answered Oct 08 '22 17:10

Derek Soike