Enable automatic branch merging for a single repositoryGo to Repository settings > Branches. Under Automatic merging, select the On status and then select Save.
Thus, if you want to ensure your branch is not changed or updated by the merge command, use --no-ff with --no-commit.
You can indeed "merge" a branch B into branch A without having to check out branch A, but only if it's a fast-forward merge.
You can use a refspec with fetch
to do the "merge". If merging branch B into branch A using git merge
would result in a fast-forward merge, then you can do the following without having to checkout A:
git fetch <remote> B:A
The above matches the refspec format
git fetch <remote> <source>:<destination>
From the documentation for git fetch
(emphasis mine):
The remote ref that matches
<src>
is fetched, and if<dst>
is not empty string, the local ref that matches it is fast-forwarded using<src>
.
Git checkout and merge without touching working tree
Merge, update, and pull Git branches without using checkouts
Merging without changing the working directory
Merging Branches Without Checkout
Enter git-forward-merge:
Without needing to checkout destination,
git-forward-merge <source> <destination>
merges source into destination branch.
https://github.com/schuyler1d/git-forward-merge
You can't merge into a branch in the general case without having it checked out. There's a good reason for this, however. You need the proper working tree in order to denote and resolve merge conflicts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With