Can I extend a git command with custom flags?

I would like to add my own flag to an existing git command. Is this doable?

Something like git diff --myownthing.

  • Nested git repositories without submodules?
  • How do I rollback to a specific git commit
  • git cant resolve rebase conflicts as mergetool doesnt pop up
  • Rebasing to change parent of a merge commit
  • Git https:// repository not found though it exists
  • How can I clone a private Gitlab repo?
  • How would I do this?

  • Composer not finding privately hosted package
  • SourceTree - how to checkout to remote repo branch
  • Alias for unpushed commits, no matter what branch I'm on?
  • git archive from changed files on bare repos
  • Git-flow fails with “fatal: no tag message? / Tagging failed. Please run finish again to retry”
  • Android studio gradle, error: Cause: error=2, No such file or directory
  • 3 Solutions collect form web for “Can I extend a git command with custom flags?”

    I’m not sure if you can modify the built-in Git commands to accept additional parameters without actually modifying Git source code, but you can easily make Git aliases that will accept parameters.

    See, for example:


    Git aliases are specifically not permitted to override git commands.

    Command aliases for the git(1) command wrapper – e.g. after defining “alias.last = cat-file commit HEAD”, the invocation “git last” is equivalent to “git cat-file commit HEAD”. To avoid confusion and troubles with script usage, aliases that hide existing git commands are ignored. Arguments are split by spaces, the usual shell quoting and escaping is supported. quote pair and a backslash can be used to quote them.

    If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command. For example, defining “ = !gitk –all –not ORIG_HEAD”, the invocation “git new” is equivalent to running the shell command “gitk –all –not ORIG_HEAD”. Note that shell commands will be executed from the top-level directory of a repository, which may not necessarily be the current directory. GIT_PREFIX is set as returned by running git rev-parse –show-prefix from the original current directory. See git-rev-parse(1).

    In your .gitconfig file you can define bash functions as aliases. I’m not sure if you could get the functionality you want but you could make git pull perform some other steps as well as /instead of the default.

    For instance I have diff = "!f() { git diff --color=always "$@" | less -R; }; f" as an alias which pipes git diff to less rather than stdout.

    Git Baby is a git and github fan, let's start git clone.