14 Viewing Branches

You need to be able to see what branches your repository has in it so you can switch between them. You can use a visualization tool such as gitk[13] or GitX.[14] You can use git branch to get the same information, however.

You can view local, remote, or all branches depending on which parameters you pass to git branch. Calling git branch by itself shows you your local branches. You can add either the -r parameter or the -a parameter to view only the remote branches or all the branches, respectively.

Your current branch always has an asterisk before it in the output from git branch. It’s colored green if you turned on color output (see Task 2, Configuring Git). Likewise, remote branches are colored red if colors are on.

One gotcha with remote branches is that the output from git branch -a shows their name with a remotes/ prefix. git branch -r doesn’t. You can use either name with commands that require a branch name.

It’s useful to see what branches have or have not been merged into the current branch. You can see that by using the --merged and --no-merged parameters.

It’s also useful to be able to find out which branches contain a particular commit. For example, you can track which branches contain a commit that has a known bug in it by using the --contains parameter.

What To Do...
  • View all local branches.
     
    prompt>​ git branch
     
    master
     
    new
     
    newer
     
    * newest
  • View all remote branches.
     
    prompt>​ git branch -r
     
    origin/master
  • View all branches.
     
    prompt>​ git branch -a
     
    master
     
    new
     
    newer
     
    * newest
     
    remotes/origin/master
  • View all that are or are not merged into the current branch.
     
    prompt>​ git branch --merged
     
    prompt>​ git branch --no-merged
  • View all branches that contain a particular commit.
     
    prompt>​ git branch --contains <commit id>

Related Tasks

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.93.0