16

I've seen people doing

git merge

i.e. using "git merge" with no arguments. It looks like it might do something useful. But I couldn't find documentation for this scenario on git-scm.com.

What does "git merge" do in this scenario?

zgpmax
  • 2,777
  • 15
  • 22

1 Answers1

15

It would try and merge its upstream branch (git merge)

If no commit is given from the command line, merge the remote-tracking branches that the current branch is configured to use as its upstream.

So check, to see if a branch has an upstream repo associated to it:

git config remote.$(git config branch.$(git symbolic-ref --short HEAD).remote).url

This uses:


For Windows, crashneb suggests in the comments:

for /f %b in ('git symbolic-ref --short HEAD') do \
  @(for /f %r in ('git config branch.%b.remote') do \
    @(git config remote.%r.url))
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 4
    Ahhhh riiiiight. It *is* documented, just in a completely unintuitive place. I was scouring the 'Description' section on the grounds that 'no arguments' is a fundamentally different invocation than 'one or more commits specified'. But it's actually documented under the '' argument. Docs could be improved IMO – zgpmax Sep 15 '16 at 07:25
  • Just in case someone wants a "windows cmd" version that chains it all together like the above: `for /f %b in ('git symbolic-ref --short HEAD') do @(for /f %r in ('git config branch.%b.remote') do @(git config remote.%r.url))` (although even on windows the bash syntax above works fine as an alias in the _.gitconfig_ file) – CrashNeb Nov 13 '21 at 00:41
  • @CrashNeb Thank you. I have included your comment in the answer for more visibility. – VonC Nov 13 '21 at 01:28