Search code examples
gitgit-remote

How does "remote tracking" work in Git?


When I clone a repository, I can read in Git Extensions if my local version is in sync with the origin version:

enter image description here

When I simply copy a repo and define it as a remote afterwards, there is no such information.

How does this "remote tracking" work?


Solution

  • Defining a remote only writes a couple of lines in the configuration file of the local repo. It doesn't contact the remote repo.

    You have to git fetch from the remote, to let the local repo know about the branches of the remote repo.

    Then you have to use git branch --set-upstream-to to tell it that a local branch must track a remote branch.

    git remote add origin <path-to-the-source-repo>
    git fetch origin
    git branch --set-upstream-to=origin/master master