-1

In git,

  • how are a remote branch and a remote tracking branch set to correspond to each other?

  • how are a remote tracking branch and a local tracking branch set to correspond to each other?

Are they done during git clone?

Are they recorded as some configuration variables in some configuration files? Are they manually modifiable?

phd
  • 82,685
  • 13
  • 120
  • 165
Tim
  • 1
  • 141
  • 372
  • 590
  • 3
    Possible duplicate of [What are the differences between local branch, local tracking branch, remote branch and remote tracking branch?](https://stackoverflow.com/questions/16408300/what-are-the-differences-between-local-branch-local-tracking-branch-remote-bra) – Jonah Bishop Jan 10 '19 at 02:32
  • I am asking about how they are set up and where they are recorded, not what they are. – Tim Jan 10 '19 at 02:34
  • 1
    @Tim The answers to that question cover all that. – Schwern Jan 10 '19 at 03:48

1 Answers1

2

how are a remote branch and a remote tracking branch set to correspond to each other?

Git stores remote tracking branches in the remotes/ namespace; see git branch -avv. The names of remotes and the names of branches make git to remember what local ref corresponds to what remote branch. They are files in .git/refs/remotes/ subdirectory. After git gc/repack they're packed inside .git/objects/pack/.

Git updates remote tracking branches when contacting the remote repository during such commands as git fetch/pull/push/remote update.

how are a remote tracking branch and a local tracking branch set to correspond to each other?

Git remembers that correspondence in the local .git/config:

[remote "origin"]
        url = git@server/repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin

Now git knows remote tracking branch remotes/origin/master corresponds to local branch master.

Are they done during git clone?

Initially, yes.

Are they recorded as some configuration variables in some configuration files?

Yes, in the local .git/config.

Are they manually modifiable?

Mostly yes, though the amount of work could be high — you need to work in the directory .git/refs/remotes/ and edit .git/config. And manual operations are impossible for packed references in .git/objects/pack/. So you better use git subcommands.

phd
  • 82,685
  • 13
  • 120
  • 165