Showing posts with label git remote add. Show all posts
Showing posts with label git remote add. Show all posts

Monday, 30 January 2012

Git Remote Add


We can track multiple repositories from a single location in your local machine. Consider the steps

1) cd <my-fav-dir>
2) git init
3) git clone git@github.com:myOrg/myRepo.git
 Sets up to track the default branch of the repository just cloned with the alias origin, usually tracking master
4) Make sure by git remote show <repo_name>
origin 

Now, we want to track one more repo.
5) git remote add another_repo git@github.com:myOrg/anotherRepo.git

Now, create a local branch to track any branch in anotherRepo

6) git checkout -b anotherRepo_master another_repo/master

Now , you have made a new local branch named anotherRepo_master tracking anotherRepo's master branch and also switched to that branch.

To make sure everything is good do,

git remote -v

origin  git@github.com:myOrg/myRepo.git
another_repo  git@github.com:myOrg/anotherRepo.git

7) git add
8) git commit -a

Now, you want to push in the right repository, the syntax is

git push <repo-to-push> <local-branch-alias>:<remote-branch-to-push>

git push another_repo anotherRepo_master:master

Hope it helps.
Cheers.
Keep Blogging