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 12, 2009, 01:14 UTC
Message-ID
<76718490903111814t1ab90a39h9252d0ccf8af05c4@mail.gmail.com>
In-Reply-To
<76718490903111758l4e4bd29et379e975deb8e99bd@mail.gmail.com>
On Wed, Mar 11, 2009 at 8:58 PM, Jay Soffian <jaysoffian@gmail.com> wrote:
> http://article.gmane.org/gmane.comp.version-control.git/54822/
Let me summarize that thread as best I can.
- The branches under refs/remotes (those shown by "git branch -r") are
remote tracking branches. This is because they typically match (i.e.
track) the corresponding branch on a remote.
- The branches under refs/heads (those shown by "git branch") are your
local branches.
- Local branches can be associated with remote tracking branches in
the repo's config (.git/config). This association is done
automatically in current git when creating a new local branch based on
a remote tracking branch (e.g, git checkout -b topic origin/master or
git branch topic origin/master). (You can use --track and --no-track
to be explicit about whether or not you want the association to
happen.)
The association itself is simply an entry in the repo's .git/config. e.g.:
[branch "topic"]
        remote = origin
        merge = refs/heads/master
So, what does this entry in the .git/config do for you? A number of things:
1) git branch -v, git status, and git checkout will tell you how far
ahead/behind the local branch is from the associated remote tracking
branch.
2) git fetch, w/o arguments, will look in the config, find the remote
for the currently checked out branch, and update the configured
remote-tracking branches for said remote. This requires a bit more
explanation. In the above example, while topic is checked out, git
fetch will find that the associated remote is called "origin". It will
then update origin per its configuration, also in .git/config. e.g.:
[remote "origin"]
        url = git://git.kernel.org/pub/scm/git/git.git
        fetch = +refs/heads/*:refs/remotes/origin/*

So that tells git fetch where to fetch from, which remote branches to fetch, and where to store those branches locally. In this case, each branch under refs/heads/ on git://git.kernel.org/pub/scm/git/git.git will be fetched and stored locally as refs/remotes/origin/. Locally the branches are called "remote tracking branches".

3) git pull, w/o arguments, will run git fetch per above. It then
knows (in this example) to merge refs/remotes/origin/master into
refs/heads/topic. (The value on the "merge =" line is arguably
confusing because it is relative to where the branch is stored on the
remote, not where it is stored locally.)
HTH,
j.
Previous: Jay SoffianNext: Jay Soffian
Message 32 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.