viernes, 18 de diciembre de 2009

git clone and pull remote branches

I thought that when I pushed/pulled branches in git, I only acted on the active branch (unless I specified it).

Well, that is not (entirely) true.

The problem is that when I clone a repo, I can't specify a given branch, and git only seemed to fetch the master branch.

When you clone a repository, you fetch all branches, with all the history (I thought that happened in hg but not in git, well anyway).

What happens then, if I don't see other branches than 'master'?
git branch
And you'll only see master branch. Other branches are hidden. To see them you should type:
git branch -a

So your branches are effectively there. To use any of them, you should
git checkout -b local_branch_name origin/remote_branch_name
I think what that line does is create a new branch and filling it with the fetched branch with that name, and bind the pull and push paths to the remote ones.

Another way?

In other sources, I've found that simply pulling with:
git pull origin Branch_name
will do the same, but, when I tried it, it downloaded/extracted the files, but without changing to the branch name.


Now the question is:

What happens if I modify two branches, and then just "git push" ? will it push both branches? That's what I'll try in next days, and after a bit of experimenting, I'll post back.

Btw, here are a couple of links you can read for a bit more info.

No hay comentarios: