Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Git with multiple remote repositories?

Tags:

git

heroku

I use currently use Heroku for rails hosting which uses a Git repository for deployment. I also have a hosted Git repository that I use as my main source control for history/backup purposes. I would like to have 1 local folder that has my working copy of my application, then be able to commit my changes to either the Heroku repository, or my hosted repository when needed.

How do I do this? (note that I am familiar with how Team System does source control and am very new to Git)

like image 921
NotDan Avatar asked Jul 19 '10 00:07

NotDan


People also ask

How do I add a second remote to git?

To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at. The git remote add command takes two arguments: A unique remote name, for example, “my_awesome_new_remote_repo” A remote URL, which you can find on the Source sub-tab of your Git repo.

How many remotes can git have?

You can have as many remote repositories as you want, but you must give them different names. The repository name is different in this case. Is the the word "origin" a name that can be changed? Yep, git remote rename <old> <new> : linux.die.net/man/1/git-remote.


1 Answers

Add them both as remotes:

git remote add origin ssh://myserver.example.com/var/git/myapp.git
git remote add hosted ssh://myotherserver.example.com/var/git/myapp.git

[1] http://toolmantim.com/thoughts/setting_up_a_new_remote_git_repository

[2] http://www.kernel.org/pub/software/scm/git/docs/git-remote.html

like image 81
bstpierre Avatar answered Oct 15 '22 21:10

bstpierre