Remote branches are just like local branches, except they map to commits from somebody else’s repository. Remote branches are prefixed by the remote they belong to so that you don’t mix them up with local branches. Like local branches, Git also has refs for remote branches. Remote branch refs live in the
./.git/refs/remotes/ directory. The next example code snippet shows the branches you might see after fetching a remote repo conveniently named remote-repo:
This output displays the local branches we had previously examined but now displays them prefixed with
origin/. Additionally, we now see the remote branches prefixed with
remote-repo. You can check out a remote branch just like a local one, but this puts you in a detached
HEAD state (just like checking out an old commit). You can think of them as read-only branches. To view your remote branches, simply pass the
-r flag to the
git branch command.
You can inspect remote branches with the usual
git checkout and
git log commands. If you approve the changes a remote branch contains, you can merge it into a local branch with a normal
git merge. So, unlike SVN, synchronizing your local repository with a remote repository is actually a two-step process: fetch, then merge. The
git pull command is a convenient shortcut for this process.