1

I have Branch1, origin/Branch1, origin/Branch2, and origin/Branch3

And, I'm now on Branch1

git fetch and git pull would download the whole objects. It will cause I spend more time for downloading.

Therefore, I want to know how can I only download objects which are from origin/Branch1

My git version: 1.7.9.5

In repo tool, we can use "repo sync --current-branch" to accomplish this.

  • I'm not sure what do you mean by "only update Branch1"? Do you need to publish your local changes (`push`) or update your local copy with changes from server (`pull`)? – Ivan Nevostruev May 10 '14 at 03:26
  • What is the real problem? – matt May 10 '14 at 03:31
  • I have Branch1, origin/Branch1, origin/Branch2, and origin/Branch3 If I use git pull, it would download all objects in the whole branches. – user3343651 May 10 '14 at 03:37

3 Answers3

0

I am assuming you are running command line git and that your other branches are check out into different folders. If you will try "git fetch" and then "git merge" when you are in your Branch1 folder, that will update only that branch.

tomek
  • 1
  • This answer is ***sort of*** correct, but not quite. Git does not represent branches as folders, and you can't have more than one branch checked-out at a time. Doing a fetch and a merge will work though, as you've stated. –  May 10 '14 at 03:42
  • Oh wait, the original poster just updated the question. Now it's not the same thing. –  May 10 '14 at 03:43
  • Yes, I am aware Git does not represent branches as folders, my understand of situation in original question was that user cloned repository multiple times to separate locations to have separate check outs of branches. Maybe my understanding was not correct :) – tomek May 10 '14 at 04:42
0

If I use git pull, it would download all objects in the whole branches

Using the right refspec, it won't: see "How do I fetch only one branch of a remote git repository?"

git fetch <remotename> <remote branch>:refs/remotes/<remotename>/<local branch>

In your case:

git fetch origin Branch1:refs/remotes/origin/Branch1
git merge origin/Branch1
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Just do this:

git fetch origin Branch1
FelipeC
  • 9,123
  • 4
  • 44
  • 38
  • @BhavinNattar It does provide an answer to his question. That command only downloads objects from origin/Branch1, and he asked "I want to know how can I only download objects which are from origin/Branch1". How does it not answer that? – FelipeC May 11 '14 at 03:05