Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change github repository for Rails

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.

Updates

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.

like image 613
Oakland510 Avatar asked Dec 14 '11 07:12

Oakland510


2 Answers

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.

like image 127
manojlds Avatar answered Sep 30 '22 05:09

manojlds


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.

  • Copied the entire app folder.
  • Changed app name wherever they appear (mostly in config folder, google it for a list)
  • Chang secret.yml file (get a new key by rake secret) or secret token if older version of rails.

Most importantly, there should be a .git folder in your app folder (it maybe hidden).

  • Delete that .git folder (it contains git info of the old app)
  • Initialize a new git, git init
  • and then commit and push.

Your new app should be a separate app now.

like image 21
Thupten N Chakrishar Avatar answered Sep 30 '22 07:09

Thupten N Chakrishar