0

Is there a way to set a global setting for git where you can specify it to to do particular prefix before every time I do something?

Say whenever I am commiting anything, I want to set a global setting in git where -S would be executed every time I commit anything. Is there a way to do this? If yes, how?

  • Not sure I got precisely what you want to obtain, but to enforce a specific prefix in your commit messages, maybe consider [a commit-msg hook](https://stackoverflow.com/questions/54077959/parse-branch-name-initiate-commit-with-name-in-the-commit-message/54078057#54078057)? – Romain Valeri Aug 20 '19 at 11:59
  • I am not sure I understand completely, but maybe you are looking for [git hooks](https://git-scm.com/docs/githooks)? A git hook is essentially a shell script which you can write yourself, and it will be executed when some specific trigger occurs. For example, you could write a `pre-commit` hook. This script would be triggered each time you run `git commit`, before the commit is made. Or you could write a `post-commit` hook which will be executed after a commit is made. – Alderath Aug 20 '19 at 12:00

3 Answers3

1

You can't generally change the default options for a command.

In many cases - including your example, and a lot of the cases where it makes sense to want to change the default behavior of a command - you can set options in git config. It's not one general option to modify the command line, which seems to be what you're asking; but rather for any given behavior, there is likely a config option that sets that behavior specifically. See the git config docs for a list of available options.

Also, you can generally create aliases (see git alias) to make them equivalent to a command with particular options.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
0

It is not possible to override a built in command, and not possible set default arguments for them either. However, for this specific case, you can easily create an alias In your ~/.gitconfig

Add something like this:

[alias]
commits = commit -s 

should do it.

Which you would then use like this:

git commits 
saidaspen
  • 560
  • 1
  • 5
  • 13
0

You can do this

git config --global --add commit.gpgSign true

or in ~/.gitconfig

[commit]
  gpgSign = true

Refer man git-config for other useful variables that you can utilise.

Sam Daniel
  • 1,800
  • 12
  • 22