Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

I know I can do git branch --all, and that shows me both local and remote branches, but it's not that useful in showing me the relationships between them.

How do I list branches in a way that shows which local branch is tracking which remote?

1 Answer

0 votes
by (50.2k points)

Reference: https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt-emltbranchnamegtupstreamemegemmasterupstreamememuem 

“[<branchname>]@{push}, e.g. master@{push}, @{push}

The suffix @{push} reports the branch "where we would push to" if git push were run while branchname was checked out (or the current HEAD if no branch name is specified). Since our push destination is in a remote repository, of course, we report the local tracking branch that corresponds to that branch (i.e., something in refs/remotes/).”

From the above documentation clearly mentions that you can find the upstream of the branch using:

git rev-parse --symbolic-full-name @{upstream}

refs/remotes/origin/master

Example: 

git rev-parse --abbrev-ref master@{upstream}

Browse Categories

...