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

GitGithub

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

As Deefour says, your situation isn't much unlike the one in https://stackoverflow.com/questions/2432764/how-to-change-a-remote-repository-uri-using-git. 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.

Solution 2 - Git

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.
  1. 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
  1. Rename the local repository's current 'origin' to 'upstream'.
  • git remote rename origin upstream
  1. Give the local repository an 'origin' that points to your repository.
  • git remote add origin https://github.com/your-account/your-repository.git
  1. 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.

Solution 3 - Git

Delete git and re-init.

Your purpose is probably to put this repo on yours and make it yours.

The idea is to delete the .git/ and re-initialize.
  1. go to your cloned repo folder
rm -rf .git
  1. re-initialize it and then add your remote and do your first push.
    git init
    git add .
    git commit -m "your commit message"
    git remote add origin 
    git push origin master

Solution 4 - Git

You can do this by creating a new remote from your local repository (via commandline).

git remote add <name> <url>

then you can call:

git push <name> <repo_name>

To replace the default "origin" remote that is set up you can run the following:

git remote rm origin
git remote add origin <url>

Solution 5 - Git

I think that the "most polite way" to do so would be:

  1. Fork the original repo on your GitHub account
  2. Checkout a new branch for your changes git checkout -b <your_branch_name> (in case you didn't do that before)
  3. Add a new remote for your local repository: git remote add github <your_repository_ssh_url>
  4. Push your beautiful new branch to your github repository: git push github <your_branch_name>

In this way you will have a repo forked to the original one, with your changes commited in a separate branch. This way will be easier in case you want to submit a pull request to the original repo.

Solution 6 - Git

Taken from https://stackoverflow.com/questions/7630574/git-push-everything-to-new-origin

basically you have to associate a new repo to your folder

git remote add origin <address>
git push origin <branchname>

Solution 7 - Git

I had a similar situation, but in my case what I just needed to do was, as suggested, but with https, like this:

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

Solution 8 - Git

After cloning, copy the files from their folder into a new one and start afresh with git init,

I had a similar problem like that I had to change the folder directory before I could stage the changes to my repo.

or you can remove current repository origin by the command git remote remove origin.

Solution 9 - Git

To save messing, I usually do this

  1. Clone it to a temp directory
  2. Create a new git repo with a README
  3. Clone that repo to my machine
  4. Delete all the git files from the original
  5. Copy all files to my repo
  6. Push it

Carry on as normal there and you can't be tripped up by issues with git. I do this fairly often. Certainly not as 'pure' as the other answers, but trauma free and removes any potential problems you may have.

Solution 10 - Git

I have the same problem. If you just want the files in the repo and push them just as if they were normal files, you can..

  1. Download zip
  2. Open terminal (or cmd on windows)
  3. Delete the .github and .gitigore files (rm -r .github)(rm .gitigore)
  4. Copy and paste the directory into your project
    Github won't know that these are from another repo since the config files are gone.

It's doesn't have the hassle of messing too much with the command line and running into problems.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjackerman09View Question on Stackoverflow
Solution 1 - GitmgarciaisaiaView Answer on Stackoverflow
Solution 2 - GitDerek SoikeView Answer on Stackoverflow
Solution 3 - GitMAOXUView Answer on Stackoverflow
Solution 4 - Gitbmorgan21View Answer on Stackoverflow
Solution 5 - GitlleknView Answer on Stackoverflow
Solution 6 - GitEric CView Answer on Stackoverflow
Solution 7 - Gituser3685927View Answer on Stackoverflow
Solution 8 - GitF. X. BlanksonView Answer on Stackoverflow
Solution 9 - GitXineBBSAView Answer on Stackoverflow
Solution 10 - Gituser18004704View Answer on Stackoverflow