threads / discuss / 6882

Where/how to create tracking branches?

Subject: Where/how to create tracking branches?

## tl;dr

4 messages between Feb 19, 2007 and Feb 19, 2007.

replies: 3people: 2as markdown or json

Bill Lear· Feb 19, 2007, 16:45 UTC · lore

What is the recommended way to create tracking branches in my private repo if I first create the corresponding topic branch in my private repo and want to publish it via a public repo?

Scenario:

[my private repo] % git checkout -b topic [work, work, work, commit] % git push /public/repo/project topic:topic

[somebody else:] % git clone /public/repo/project % git checkout -b topic origin/topic [work, work, work, commit] % git push /public/repo/project topic:topic

[my private repo]
% git checkout topic
% git pull /public/repo/project topic
remote: Generating pack...
remote: Done counting 5 objects.
Result has 3 objects.
remote: Deltifying 3 objects.
remote: /3) done/3) done
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking 3 objects
 100% (3/3) done
Updating 4751fcc..2d92737
Fast forward
 A |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
% git branch
  master
* topic
% git branch -r
  origin/HEAD
  origin/master

Now, I'm on my private repo, but I really want a tracking branch for doing pulls from my public repo, or peers, for this topic branch.

Do I have to create the topic branch in my public repo first? This seems crazy, as our company repo is just another "global" public repo and each developer would need to create branches there instead of on their own machine.

I tried this:
% git pull /public/repo/project topic:origin/topic

But it created a topic branch named "origin/topic" instead of a tracking branch.

Bill
Junio C Hamano· Feb 19, 2007, 19:43 UTC · re: Bill Lear · lore

Re: Where/how to create tracking branches?

Bill Lear <rael@zopyra.com> writes:
Show 10 quoted lines
> What is the recommended way to create tracking branches in my private
> repo if I first create the corresponding topic branch in my private
> repo and want to publish it via a public repo?
>
> Scenario:
>
> [my private repo]
> % git checkout -b topic
> [work, work, work, commit]
> % git push /public/repo/project topic:topic

So at this point the public shared repository has refs/heads/topic branch you and colleagues can work on together. So I am puzzled about this part...

> Do I have to create the topic branch in my public repo first?  This
> seems crazy,...
because you did do so and I do not think it is crazy.

Maybe you meant "do I create tracking branch for 'topic' in public?", in which case the answer is no.

Show 6 quoted lines
> I tried this:
>
> % git pull /public/repo/project topic:origin/topic
>
> But it created a topic branch named "origin/topic" instead of a tracking
> branch.

Assuming your clone was initially made from /public/repo/project, doesn't "git fetch" without _any_ parameter work?

	$ git fetch
Bill Lear· Feb 19, 2007, 20:13 UTC · re: Junio C Hamano · lore

Re: Where/how to create tracking branches?

On Monday, February 19, 2007 at 11:43:36 (-0800) Junio C Hamano writes:
Show 5 quoted lines
>...
>Assuming your clone was initially made from /public/repo/project,
>doesn't "git fetch" without _any_ parameter work?
>
>	$ git fetch

Short answer: yes, it does. I had assumed I needed to create the tracking branch somehow since I created the topic branch in the first place in my private repo. More detailed confirmation follows, but thank you for pointing out that git is in fact smarter than I gave it credit.

# set up a public repo with "master" branch and something in it... mkdir public_repo && cd public_repo && git --bare init cd .. mkdir a_repo && cd a_repo && git init echo A > A && git add A && git commit -a -m A git push ../public_repo master:master

# clone public repo to get my private repo, create topic branch cd .. git clone public_repo private_repo cd private_repo git checkout -b topic echo change >> A && git commit -a -m change

# publish my branch 'topic' to my public repo git push ../public_repo topic:topic

# A peer grabs the topic branch, makes changes and pushes back to public cd .. git clone public_repo peer_repo cd peer_repo git checkout -b topic origin/topic echo more >> A && git commit -a -m more git push ../public_repo topic:topic

# Go to my private repo, pull latest changes (show output this time...)
cd ../private_repo
git checkout master
git pull
remote: Generating pack...
remote: Done counting 5 objects.
Result has 3 objects.
remote: Deltifying 3 objects.
remote: /3) done/3) done
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking 3 objects
 100% (3/3) done
* refs/remotes/origin/topic: storing branch 'topic' of /home/blear/test/public_repo
  commit: 4a8e157
Already up-to-date.

# Now, switch to topic branch git checkout topic cat A A change

# Ok, now I get it: git diff origin/topic [changes listed] git merge origin/topic cat A A change more

Bill
Junio C Hamano· Feb 19, 2007, 21:09 UTC · re: Bill Lear · lore

Re: Where/how to create tracking branches?

Bill Lear <rael@zopyra.com> writes:
Show 12 quoted lines
> On Monday, February 19, 2007 at 11:43:36 (-0800) Junio C Hamano writes:
>>...
>>Assuming your clone was initially made from /public/repo/project,
>>doesn't "git fetch" without _any_ parameter work?
>>
>>	$ git fetch
>
> Short answer: yes, it does.  I had assumed I needed to create the
> tracking branch somehow since I created the topic branch in the first
> place in my private repo.  More detailed confirmation follows, but
> thank you for pointing out that git is in fact smarter than I gave
> it credit.

Tracking new branches on the remote side after you create a clone is one of the few things 1.5.0 does much better than 1.4.4 series, and it was done in response to comments from real world users like yourself, so rather than giving git too much credit, I think you should take it yourself ;-).

← back to recent threads