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

Sunday 29 January 2012

GIT PATCH FILE

Well , this is quick and dirty. Probably, I will add more information to it. But suppose consider the following:

Your manager says that he/she wants the digest of the commit you have just made before pushing the code to the repository. He/She will review it and tell more about it. You can probably zip your changed files and send him/her to review.

Git comes with a really nice alternate, the git patch files. To come up with it, just
do:

1) git add
2) git commit -a
3) git format-patch -1

-1 says that you want to create a patch file(containing all the git diffs) for the last commit.

-2 creates a patch file for 2 most recent commits and so on.

Now, he/she can just do

git apply <patch file path which you probably emailed>

That would create an exact same commit at his end and then she can see all the code that you have just written for a new critical feature/bug.
Please post any questions or updates.

Hope it helps.
Keep blogging
Cheers