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.

  • Include Git Library with Project on Android Studio using aar?
  • Make git ignore modification date changes if the content of the file stays the same
  • Synchronizing copied repository with GIT repository
  • Cannot rewrite branches:git
  • git diff not comparing as expected
  • GIT: fatal: Not a git repository
  • How would I do this?

  • Pushing new Git branches and subsequently merging them on the origin
  • How to cherry-pick a branch that contains merges
  • Git Update Hook: Finding all files being pushed to a new branch
  • Cannot push to github with Powershell
  • How to remove a directory level from a GIT repo?
  • The following untracked working tree files would be overwritten by merge, but I don't care
  • 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.