Reputation: 2630
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?
Upvotes: 132
Views: 223805
Reputation: 1
In addition to the steps mentioned in @Derek Soike's answer, you can change the default configured remote in order to use push and pull without specifying origin: (for branch named main)
git config branch.main.remote
expected output for our case: upstream
git config branch.main.remote origin
Upvotes: 0
Reputation: 389
Your purpose is probably to put this repo on yours and make it yours.
.git/
and re-initialize.rm -rf .git
git init
git add .
git commit -m "your commit message"
git remote add origin <address>
git push origin main
Upvotes: 25
Reputation: 780
Simply:
git remote add origin https://github.com/your-username/name-of-repo.git
git branch -M main
git push -u origin main
UPDATE:
Or master
instead of main
depends on the name of your master branch.
Upvotes: 0
Reputation: 99
This worked for me as of December 2022. Straight forward
I cloned the repo and then create a new repo on GitHub with a new name and no file
I duplicated the folder and renamed it
In the terminal (within the folder), rm -rf .git
to del all existing git files
I git init
to initialize
I git add -- . ': path'
where the path was a directory with large weights I did not want to commit. It causes an error if you add all
git commit -m "message"
git remote add origin https://github.com/xxx/xxxx.git
to newly created repo
git branch -M main
git push -u origin main
Upvotes: 0
Reputation: 69
Using vscode, these other solutions did not quite work for me,
Instead, I ran
git init
This will make it so that the 'new branch' button makes a completely new repository when you go to commit. I could not figure out how to commit into an already uninitialize repository.
edit : Since i was following a tutorial, i'm not very experienced with git, The flags were the culprit Remote rejected (shallow update not allowed) after changing Git remote URL
Upvotes: 0
Reputation: 11650
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.
git clone https://github.com/other-account/other-repository.git
git remote rename origin upstream
git remote add origin https://github.com/your-account/your-repository.git
git push origin main
Now 'origin' points to your repository & 'upstream' points to the other repository.
git checkout -b my-feature-branch
.git commit
as usual to your repository.git pull upstream main
to pull changes from the other repository to your main branch.Upvotes: 125
Reputation: 553
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..
It's doesn't have the hassle of messing too much with the command line and running into problems.
Upvotes: -1
Reputation: 1
To save messing, I usually do this
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.
Upvotes: 0
Reputation: 11
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.
Upvotes: 1
Reputation: 3301
I think that the "most polite way" to do so would be:
git checkout -b <your_branch_name>
(in case you didn't do that before) git remote add github <your_repository_ssh_url>
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.
Upvotes: 10
Reputation: 21
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
Upvotes: 2
Reputation: 15570
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.
Upvotes: 194
Reputation: 119
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>
Upvotes: 8
Reputation: 2205
Taken from 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>
Upvotes: 1