1

Is there a way to display the current merge config option in git without manually specifying the current branch I am in. I am wanting to do something like this:

$ git cur-merge-val
branch.current.merge = /refs/heads/current

where git cur-merge-val could be some long, complicated series of git commands to which I can make an alias for -- so long as what I personally type on the command line doesn't require typing the current branch I'm in (because that seems redundant since that information should be programmatically accesible somehow).

Alexander Bird
  • 38,679
  • 42
  • 124
  • 159

2 Answers2

1

Create the following script (e.g., call it cur-merge-val.sh and make it executable):

current=`git status -s -b | head -1 | cut -d' ' -f2`
git config branch.$current.merge

Then, just add the following to your .gitconfig file:

[alias]
cur-merge-val = /path/to/cur-merge-val.sh

Ben Hocking
  • 7,790
  • 5
  • 37
  • 52
0

I found a solution which:

  1. avoids porcelain commands in favor of plumbing commands
  2. shows also the current remote config value and all possible merge config values if there are multiple of them.
  3. avoids having to make another executable file

see https://stackoverflow.com/a/1593487/10608 for a reference of why I get current branch name the way I do.

[alias]
    cur-merge-val = !branch_name="$(git symbolic-ref HEAD)" && branch_name=${branch_name##refs/heads/} && git config --get-all branch.$branch_name.remote; git config --get-all branch.$branch_name.merge
Community
  • 1
  • 1
Alexander Bird
  • 38,679
  • 42
  • 124
  • 159