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.

  • Removing/undoing a merge on Sourcetree
  • git bash fail to push branch with error message: “object directory does not exist”
  • How to discard change to git submodule?
  • How to suppress the editor for `git rebase --continue`?
  • ExpressionEngine : git : local development : remote database
  • Unification of DVCS commands
  • 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 git@github.com: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 git@github.com: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.

  • Why is the git index file binary?
  • Git Push Error: insufficient permission for adding an object to repository database
  • Git recursive mv files
  • Is it possible to mirror a private repository on gitlab.com using the SSH protocol?
  • SSH is looking in the wrong place for the public/private key pair on Windows
  • How do I edit an existing tag message in git?
  • 4 Solutions collect form web for “Change github repository for Rails”

    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.

    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.

    I think this might work if on heroku, worth a try:

    git remote rm heroku
    git remote add heroku git@heroku.com: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 = git@heroku.com:old_app_name.git
    

    to

    url = git@heroku.com:new_app_name.git
    

    Obviously substituting your apps old name to its new name. Hope it helps

    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/

    Git Baby is a git and github fan, let's start git clone.