git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: setting up tracking on push

From
Jay Soffian <jaysoffian@gmail.com>
Date
Mar 15, 2009, 12:36 UTC
Message-ID
<76718490903150536r2d3e687ckbcc4e1bdb2d2194d@mail.gmail.com>
In-Reply-To
<4845-91917@sneakemail.com>

On Sat, Mar 14, 2009 at 11:28 PM, John M. Dlugosz <ngnr63q02@sneakemail.com> wrote:

> Things under refs/remotes are remote tracking branches
Yes.
> and local branches
> (under refs/heads) that automatically updated based on a fetch ("store
> locally" means merge or rebase, right?) are also called remote tracking
> branches.
No. The branches under refs/heads are *not* [1] updated by fetch.
- Anything under refs/remotes is a remote tracking branch.
- Anything under refs/heads is a local branch.

Now, often local branches are based on remote tracking branches, in the sense that you created the local branch _from_ the remote tracking branch. So periodically, you will want to update the local branch in order to incorporate your local changes with whatever changes have been made in the remote tracking branch. Doing this is a two-step process:

1) You update your remote tracking branches using fetch.
2) You integrate the changes from the remote tracking branches into your
   local branches using either merge or rebase.
> I think that's why some of us are confused.

I remember being just as confused, but oddly it seems so clear to me now. I think there is an inflection point where git goes from "confusing" to "ah hah, it's ingenious!" :-)

Let me try to draw a little ascii art:
Local Repo                                  Remote Repo (origin)
----------                                  --------------------
refs/remotes/origin/master  <-- fetch ---   refs/heads/master
        |
(merge or rebase)
        |
        v
refs/heads/master

As changes are made to refs/heads/master on the remote repo, the corresponding remote tracking branch on the local repo (refs/remotes/origin/master) will fall behind. Performing a fetch in the local repo updates its refs/remotes/origin/master to match the remote's refs/heads/master. Then either merge or rebase in the local repo, while refs/heads/master is checked out, integrates those changes.

If no changes have been made locally to refs/heads/master, then the merge operation is a so-called "fast forward".

The confusing part is that there is a switch to "git checkout" and "git branch" named "--track". A better name would have probably been "--follow". Regardless, this switch [2], configures branch.<name>.remote and branch.<name>.merge in the local repo's .git/config. And I mentioned in a previous message the reason for having these. [3]

[1] You could of course configure fetch to do whatever you like, but it
    would be rather unusual to update refs/heads via fetch.
[2] Which is the default in current git when a local branch is created
    from a remote tracking branch.
[3] Namely, 1) branch -v, status, and checkout tell you how far
    ahead/behind the local branch is from the remote tracking branch;
    2) pull can be run w/o having to explicitly tell it what to fetch
    and what to merge.
j.
Previous: John M. DlugoszNext: John M. Dlugosz
Message 35 of 38 in “setting up tracking on push”
  1. Miles BaderMar 6, 2009
  2. John TapsellMar 6, 2009
  3. Jay SoffianMar 6, 2009
  4. Johannes SchindelinMar 6, 2009
  5. Miles BaderMar 6, 2009
  6. Jeremy O'BrienMar 6, 2009
  7. Jay SoffianMar 6, 2009
  8. Miles BaderMar 6, 2009
  9. Marc BranchaudMar 10, 2009
  10. Jeff KingMar 10, 2009
  11. Jay SoffianMar 11, 2009
  12. Jeff KingMar 11, 2009
  13. Jay SoffianMar 11, 2009
  14. Jeff KingMar 11, 2009
  15. Jay SoffianMar 11, 2009
  16. Jay SoffianMar 11, 2009
  17. Jeff KingMar 11, 2009
  18. Jay SoffianMar 11, 2009
  19. Jakub NarebskiMar 24, 2009
  20. Junio C HamanoMar 11, 2009
  21. Miles BaderMar 11, 2009
  22. Miles BaderMar 11, 2009
  23. Jay SoffianMar 11, 2009
  24. Marc BranchaudMar 11, 2009
  25. Jeff KingMar 11, 2009
  26. Nanako ShiraishiMar 11, 2009
  27. Jeff KingMar 11, 2009
  28. John M. DlugoszMar 12, 2009
  29. Jay SoffianMar 12, 2009
  30. Junio C HamanoMar 12, 2009
  31. Jay SoffianMar 12, 2009
  32. Jay SoffianMar 12, 2009
  33. Jay SoffianMar 12, 2009
  34. John M. DlugoszMar 15, 2009
  35. Jay SoffianMar 15, 2009
  36. John M. DlugoszMar 16, 2009
  37. Jay SoffianMar 16, 2009
  38. Junio C HamanoMar 15, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.