Reputation: 7066
This is my understanding of Git:-
If I clone a repository then I initially only get a copy of the master branch. I can then indicate that I want to track a remote branch using git checkout
with the -b
flag. This works as expected.
So my question is how do you get Git to tell you this information. If I type git branch -a
then it shows me a mixed list of all the branches e.g.
* master
mybranch
remotes/origin/master
remotes/origin/mybranch
What I want to know is other than maintaining the same name, how can I tell what local branches are tracking what remote ones?
Thanks.
Upvotes: 1
Views: 92
Reputation: 11
Try
git branch -vv
The remote branch is displayed on the same line as the local branch that's tracking it.
Upvotes: 1
Reputation: 70235
You can see all the remote's branches and which local branches already track the remote with:
git remote show origin
Upvotes: 0
Reputation: 312650
If I clone a repository then I initially only get a copy of the master branch. I can then indicate that I want to track a remote branch using git checkout with the -b flag. This works as expected.
In fact, git checkout -b ...
is what you use to create a new branch. If you simply want to check out a branch that already exists in the remote, you don't need -b
. For example, here I'm creating a local branch that tracks remotes/origin/folder-hack
:
$ git checkout folder-hack
Branch folder-hack set up to track remote branch folder-hack from amdragon.
Switched to a new branch 'folder-hack'
What I want to know is other than maintaining the same name, how can I tell what local branches are tracking what remote ones?
Each branch has a corresponding configuration in .git/config
. You can find the remote associated with a branch by looking at branch.<BRANCHNAME>.remote
, and you can find the name of the remote branch by looking at branch.<BRANCHNAME>.merge
. So, from my previous example:
$ git config --get branch.folder-hack.remote
amdragon
$ git config --get branch.folder-hack.merge
refs/heads/folder-hack
You can just run git config --list
and look at the branch...
lines.
Upvotes: 5