180

I'm trying to follow some tutorials to learn how to use Git but some of the instructions are for specific versions.

Is there a command that I can use find out what version I have installed?

cloudfeet
  • 12,156
  • 1
  • 56
  • 57
Paul Sheldrake
  • 7,505
  • 10
  • 38
  • 50

7 Answers7

279
$ git --version
git version 1.7.3.4

git help and man git both hint at the available arguments you can pass to the command-line tool

Gareth
  • 133,157
  • 36
  • 148
  • 157
  • 1
    For people that don't know nothing about git console. Just write 'git --version' . Without the dollar ($) and quation marks ('') – Hanako May 17 '19 at 16:40
21

If you're using the command-line tools, running git --version should give you the version number.

Gnat
  • 2,861
  • 1
  • 21
  • 30
19

Or even just

git version

Results in something like

git version 1.8.3.msysgit.0

nawfal
  • 70,104
  • 56
  • 326
  • 368
19

In a command prompt:

$ git --version
rachel
  • 191
  • 3
2

From Gareth's answer:

git help and man git both hint at the available arguments you can pass to the command-line tool

Actually, the git version command finally gets an official help page with Git 2.34 (Q4 2021):

See commit b6d8887 (14 Sep 2021) by Matthias Aßhauer (rimrul).
(Merged by Junio C Hamano -- gitster -- in commit 188da7d, 23 Sep 2021)

documentation: add documentation for 'git version'

Signed-off-by: Matthias Aßhauer

While 'git version'(man) is probably the least complex git command, it is a non-experimental user-facing builtin command.
As such it should have a help page.

Both git help(man) and git version can be called as options (--help/--version) that internally get converted to the corresponding command.
Add a small paragraph to Documentation/git.txt describing how these two options interact with each other and link to this help page for the sub-options that --version can take.
Well, currently there is only one sub-option, but that could potentially increase in future versions of Git.

git version now includes in its man page:

git-version(1)

NAME

git-version - Display version information about Git

SYNOPSIS

git version [--build-options]

DESCRIPTION

With no options given, the version of 'git' is printed on the standard output.

Note that git --version is identical to git version because the former is internally converted into the latter.

OPTIONS

--build-options

Include additional information about how git was built for diagnostic purposes.

git now includes in its man page:

This option is internally converted to git version ... and accepts the same options as the git version command.
If --help is also given, it takes precedence over --version.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Since git 2.37.0 you can also simply use git -v

idanakav
  • 1,466
  • 1
  • 13
  • 23
-4
which git &> /dev/null || { echo >&2 "I require git but it's not installed.  Aborting."; exit 1; }
echo "Git is installed."

That will echo "Git is installed" if it is, otherwise, it'll echo an error message. You can use this for scripts that use git

It's also customizable, so you can change "which git" to "which java" or something, and change the error message.

Lee Ikard
  • 84
  • 11