user1245262
user1245262

Reputation: 7505

Why do I have multiple tracking branches on a remote git repository?

I'm about to perform an update of a fork I made a while back for a github project. When I tried to look at the remote repository, I saw this:

me@Bedrock:~/Downloads/git_proj/git_proj$ git remote show origin
* remote origin
  Fetch URL: https://github.com/jsmith/git_proj.git
  Push  URL: https://github.com/jsmith/git_proj.git
  HEAD branch: master
  Remote branches:
     api-consistency               new (next fetch will store in remotes/origin)
     gp-1                          tracked
     gp-2                          new (next fetch will store in remotes/origin)
     master                        tracked
     refs/remotes/origin/new_conv_ops stale (use 'git remote prune' to remove)
     revert-6817-getfullargspec    new (next fetch will store in remotes/origin)
     tf-gp                         new (next fetch will store in remotes/origin)
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date)

I do not understand why multiple branches are shown as being tracked. Shouldn't I only be tracking the master branch? If so, why is the gp-1 branch shown as being tracked? Does it just mean I could track this branch if I wanted to?

Am I correct in believing that my local master branch will push to/pull from the remote master branch, but that if I wanted, I could have other local branches push/pull from an arbitrary remote branch?

Upvotes: 0

Views: 153

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522752

The Git documentation on working with remotes explains your output well. To repeat your output here:

HEAD branch: master
Remote branches:
   api-consistency               new (next fetch will store in remotes/origin)
   gp-1                          tracked
   gp-2                          new (next fetch will store in remotes/origin)
   master                        tracked
   refs/remotes/origin/new_conv_ops stale (use 'git remote prune' to remove)
   revert-6817-getfullargspec    new (next fetch will store in remotes/origin)
   tf-gp                         new (next fetch will store in remotes/origin)

Branches which are labelled as tracked, e.g. gp-1, are those branches which exist on the remote and which you have already pulled locally. On the other hand, branches labelled as new mean that they exist on the remote but you do not yet have them locally.

Also, the HEAD branch being labelled as master means that master is the default branch for certain operations, such as git pull. If you issue a git pull locally, but not explicitly specify a branch to be merged in, then master will be used.

Upvotes: 1

smac89
smac89

Reputation: 43234

You are on branch master. All your push and pull will be done to master. Delete the branches you don't want with:

git branch -d <branch name>

To delete them remotely, use:

git push origin --delete <branch name>

To change where any branch pushes/pulls from, use:

git branch --set-upstream <your_local_branch> <your_new_remote/branch_name>

Upvotes: 0

Related Questions