How to pull push from multiple git repositories
A lot of time I have seen people asking how to handle two git repo from the same directory. It seems pretty simple as most of them have pushed much application on Heroku. So on regular basis, they keep pushing code to GitHub or Bitbucket and once everything is tested out, they push their code on Heroku. Which is exactly what they are asking.
Ok, enough with the stories, it’s all about setting a new different origin. Let me explain this via Heroku example. When you are using Github, to push the code on master branch you do it via
git push origin master
Now to push it on Heroku, you do
git push heroku master
Here you are doing the same, pushing the code to different repositories where things are different from two origin points ie Heroku and origin :). So let’s assume we have two repositories ie repository_1 and repository_2 with remote URLs git@github.com:mohitjain/repository_1.git and git@github.com:mohitjain/repository_2.git respectively.Now setup two different origins in your local git repository
git remote add origin_1 git@github.com:mohitjain/repository_1.git
git remote add origin_2 git@github.com:mohitjain/repository_2.git
Now you can push on repository_1 by:
git push origin_1 master
and in another repository_2 by:
git push origin_2 master
Similarly, you can pull from different repositories. Or create aliases something like this (Be careful while doing this):
alias pushall='for i in `git remote`; do git push $i; done;'
alias pullall='for i in `git remote`; do git pull $i; done;'