Pull and Push Code From Different Repositories
A git repository has a remote origin where the code is pushed regularly. By default we have one remote origin. But some cases may require different origins e.g. My blog has its remote origin set to heroku. Comamnd
git push origin master
git push heroku master
Because both are pointed to same origin as we can see from
git remote -v show
heroku git@heroku.com:my_blog_repo.git (fetch)
heroku git@heroku.com:my_blog_repo.git (push)
origin git@heroku.com:my_blog_repo.git (fetch)
origin git@heroku.com:my_blog_repo.git (push)
Now, I want to keep a backup of everything apart from hosting on heroku lets say on my bitbucket repository. Simply add another
git remote add origin2 git@bitbucket.org:grsahil20/my_blog_repo.git
resultant is
git remote -v show
heroku git@heroku.com:my_blog_repo.git (fetch)
heroku git@heroku.com:my_blog_repo.git (push)
origin git@heroku.com:my_blog_repo.git (fetch)
origin git@heroku.com:my_blog_repo.git (push)
origin2 git@bitbucket.org:grsahil20/my_blog_repo.git (fetch)
origin2 git@bitbucket.org:grsahil20/my_blog_repo.git (push)
Now, code can be pushed to git repository hosted at bitbucket via
git push origin2 master
Happy Gitting :)