Information Technology Reference
In-Depth Information
The information containing which branches are merged and which are not merged in
the current branch can be obtained with the --merged and --no-merged options
passed to the $ git branch command:
# print the names of branches merged in current branch
$ git branch --merged
# print the names of branches not merged in current branch
$ git branch --no-merged
Now that you know about merged and not merged branches you can easily guess
that the command:
$ git branch -d [branch-name]
deletes a given branch only if it is merged in a current branch. If the branch you want
to delete is not merged the command prints a warning:
error: The branch 'branch-name' is not fully merged.
and then exits. The command with the -D option:
$ git branch -D [branch-name]
removes a branch even if it is not merged.
Let me remind you that a branch is a simple pointer—just a SHA-1 stored in either a
loose or packed format. If you create a branch, git stores a new pointer inside the .git
directory. When a branch is deleted the pointer is removed. The commands $ git
branch -d and $ git branch -D do not modify the database. All the revisions
are left intact. Therefore, even if you delete a branch you can retrieve it using reflog.
Note This recipe describes the way to delete local branches. You can use it to delete
ordinary local branches and local tracking branches. All remote tracking branches can
be deleted with the $ git remote rm command, as we did in Recipe 5-2. To delete
only one remote tracking branch origin/doc you can use $ git branch -d -r origin/doc
command. But remote tracking branches deleted with $ git branch -d -r will be recreated
Search WWH ::




Custom Search