# Where/how to create tracking branches?

4 messages from 2007-02-19 to 2007-02-19. Participants: Bill Lear, Junio C Hamano.
Thread: https://gitlist.dev/t/6882

## Bill Lear, 2007-02-19 16:45

Subject: Where/how to create tracking branches?
Message-ID: <17881.54325.475907.468492@lisa.zopyra.com>
URL: https://gitlist.dev/e/17881.54325.475907.468492%40lisa.zopyra.com

```
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, 2007-02-19 19:43

Subject: Re: Where/how to create tracking branches?
Message-ID: <7vy7mu6ihj.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vy7mu6ihj.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <17881.54325.475907.468492@lisa.zopyra.com>

```
Bill Lear <rael@zopyra.com> writes:

> 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.

> 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, 2007-02-19 20:13

Subject: Re: Where/how to create tracking branches?
Message-ID: <17882.1230.704770.12880@lisa.zopyra.com>
URL: https://gitlist.dev/e/17882.1230.704770.12880%40lisa.zopyra.com
In-Reply-To: <7vy7mu6ihj.fsf@assigned-by-dhcp.cox.net>

```
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.

# 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, 2007-02-19 21:09

Subject: Re: Where/how to create tracking branches?
Message-ID: <7v1wkl7t3b.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v1wkl7t3b.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <17882.1230.704770.12880@lisa.zopyra.com>

```
Bill Lear <rael@zopyra.com> writes:

> 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 ;-).

```
