Skip to content

How to check that branch is already merged #951

Closed Answered by pjbgf
kazhuravlev asked this question in Q&A
Discussion options

You must be logged in to vote

For --merged, I believe you would get the tip commit of your branches, then iterate through the commits of your current branch to confirm whether they can be found there.

For getting tip commits from the branches you could use something like this:

    branches, err := r.Branches()
    ...

    err = branches.ForEach(func(b *plumbing.Reference) error {
        // Skip the current branch
        if b.Name() == headRef.Name() {
            return nil
        }
        ...
        commit, err := r.CommitObject(b.Hash())

For iterating through the commits from the current branch, you could use r.Log:

    headRef, err := r.Head() // Tip of the current branch
    ...
    cIter, err := r.Log(&git.L…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@pjbgf
Comment options

Answer selected by kazhuravlev
@kazhuravlev
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants