Reputation: 1083
How do you change the git repository a rail app is pushed to? I know that this is possible because I did it a few weeks back.
Basically I have two very different versions of a app on my local machine. I would like the initial app to still point to the old repository. However, the new version needs to be placed in a completely separate repository.
When I run git init
in myapps/old_app/
it puts Reinitialized existing Git repository in /Users/jamespollard/rails/old_repository/.git/
AND
When I run git init
in myapps/new_app/
it puts Reinitialized existing Git repository in /Users/jamespollard/rails/new_repository/.git/
However, when I try and git push anything to the repository, it still goes to the old_repository.
If I enter $ git remote origin set-url [email protected]:mygithub/myapp.git
I get
error: Unknown subcommand: origin
usage: git remote [-v | --verbose]
or: git remote add [-t <branch>] [-m <master>] [-f] [--mirror=<fetch|push>] <name> <url>
or: git remote rename <old> <new>
or: git remote rm <name>
or: git remote set-head <name> (-a | -d | <branch>)
or: git remote [-v | --verbose] show [-n] <name>
or: git remote prune [-n | --dry-run] <name>
or: git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
or: git remote set-branches <name> [--add] <branch>...
or: git remote set-url <name> <newurl> [<oldurl>]
or: git remote set-url --add <name> <newurl>
or: git remote set-url --delete <name> <url>
-v, --verbose be verbose; must be placed before a subcommand
If I enter $ git remote set-url [email protected]:mygithub/myapp.git
I get the same error message as above (minus the origin error). In either case, if I run git push origin master
it still pushes to the old repository. I've tried adding the new repository again with the same name, but I get a error (which i would expect) saying that it already exists.
Upvotes: 6
Views: 6124
Reputation: 69
I ran into a pretty similar situation few months ago. On the new version of the app there is a .git folder (which was also copied along with all other files when you copied the app). Heroku needs the information from .git to see if anything has changed. So when it 'reinitialized', heroku thinks its the same app.
So here's what I did that resolved the problem.
Most importantly, there should be a .git folder in your app folder (it maybe hidden).
Your new app should be a separate app now.
Upvotes: 1
Reputation: 3283
If you take a peek at your .git/config
file, you see / check that the url is still pointing to the old remote
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = <old_github_url>
so you wish to keep the old remote. let's call that oldremote
.
First thing you can do is the rename the remote with :
git remote rename origin oldremote
Now you can add the new remote with :
git remote add origin <new_github_url>
From now on, pushing normally with just git push
will push to the new remote. git push oldremote SHA
to push to the old remote
remote reference : http://help.github.com/remotes/
Upvotes: 0
Reputation: 301147
Create a new repository in GitHub for you new app, if you haven't already. Make that new repository as origin to your new repository:
git remote add origin <github_url>
If the remote already exists, you might have to git remote set-url origin <github_url>
Now, push to the repo.
Upvotes: 5
Reputation: 3052
I think this might work if on heroku, worth a try:
git remote rm heroku
git remote add heroku [email protected]:yourappname.git
or you can try this
1). open a terminal
2). Go to your_app_directory/.git/config
3). Once you open the config file then edit as follows:
Change
url = [email protected]:old_app_name.git
to
url = [email protected]:new_app_name.git
Obviously substituting your apps old name to its new name. Hope it helps
Upvotes: 0