Git rev-parse: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 11: Line 11:
</syntaxhighlight>
</syntaxhighlight>


If inside the root of the git main work tree, return:
If inside the root of the main work tree, return:
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
.git
.git
</syntaxhighlight>
</syntaxhighlight>


If inside of a subdirectory of the main work tree, return the absolute path of the .git directory:
<syntaxhighlight lang='bash'>
/Users/someuser/my-repo/.git
</syntaxhighlight>


If inside a git linked work tree, return
If inside the root of a linked work tree, return the absolute path of the [[Git_Concepts#Linked_Tree_Private_Subdirectory|linked tree private subdirectory]] in the $GIT_DIR of the repository (main work tree):
 
<syntaxhighlight lang='bash'>
work area, return the relative path of [[Git_Environment_Variables#GIT_DIR|$GIT_DIR]] (.git in the root of the work area, absolute path from other location).
/Users/someuser/my-repo/.git/worktrees/my-linked-tree
</syntaxhighlight>


Sends  
Sends  

Revision as of 04:36, 16 July 2020

Internal

Overview

Value of $GIT_DIR

git rev-parse --git-dir

If inside the root of the main work tree, return:

.git

If inside of a subdirectory of the main work tree, return the absolute path of the .git directory:

/Users/someuser/my-repo/.git

If inside the root of a linked work tree, return the absolute path of the linked tree private subdirectory in the $GIT_DIR of the repository (main work tree):

/Users/someuser/my-repo/.git/worktrees/my-linked-tree

Sends

"fatal: not a git repository (or any of the parent directories): .git"

to stderr and return 128 return code if not in a git work area.

Currently Checked Out Branch

Return the currently checked out branch in the current work tree:

git rev-parse --abbrev-ref HEAD

Other Options

--is-inside-work-tree

Returns true if inside a working tree, including the main working tree.