Search code examples
gitmergegit-mergegit-commit

Can I merge two branches when I am in another branch?


Suppose I am in branch A. How can I merge branches B and C without checking out another branch?

Can I use this command? git merge B C


Solution

  • Nope.... you can't. For these cases, you can use temporarily a new worktree:

    git worktree add blahblah B
    cd blahblah
    git merge C
    cd ..
    git worktree remove blahblah